-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Expand file tree
/
Copy pathMemoryPackagePart.cs
More file actions
110 lines (98 loc) · 2.86 KB
/
Copy pathMemoryPackagePart.cs
File metadata and controls
110 lines (98 loc) · 2.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using NPOI.OpenXml4Net.OPC.Internal.Marshallers;
using NPOI.OpenXml4Net.Exceptions;
using NPOI.Util;
namespace NPOI.OpenXml4Net.OPC.Internal
{
public class MemoryPackagePart : PackagePart
{
/**
* Storage for the part data.
*/
internal MemoryStream data;
/**
* Constructor.
*
* @param pack
* The owner package.
* @param partName
* The part name.
* @param contentType
* The content type.
* @throws InvalidFormatException
* If the specified URI is not OPC compliant.
*/
public MemoryPackagePart(OPCPackage pack, PackagePartName partName,
String contentType)
: base(pack, partName, contentType)
{
}
/**
* Constructor.
*
* @param pack
* The owner package.
* @param partName
* The part name.
* @param contentType
* The content type.
* @param loadRelationships
* Specify if the relationships will be loaded.
* @throws InvalidFormatException
* If the specified URI is not OPC compliant.
*/
public MemoryPackagePart(OPCPackage pack, PackagePartName partName,
String contentType, bool loadRelationships) :
base(pack, partName, new ContentType(contentType), loadRelationships)
{
}
protected override Stream GetInputStreamImpl()
{
// If this part has been created from scratch and/or the data buffer is
// not
// initialize, so we do it now.
if (data == null)
{
return new MemoryStream();
}
return new MemoryStream(data.GetBuffer(), 0, (int)data.Length, writable: false);
}
protected override Stream GetOutputStreamImpl()
{
return new MemoryPackagePartOutputStream(this);
}
public override long Size
{
get
{
return data == null ? 0 : data.Length;
}
}
public override void Clear()
{
data = null;
}
public override bool Save(Stream os)
{
return new ZipPartMarshaller().Marshall(this, os);
}
public override bool Load(Stream ios)
{
// Save it
StreamHelper.CopyStream(ios, data);
// All done
return true;
}
public override void Close()
{
// Do nothing
}
public override void Flush()
{
// Do nothing
}
}
}