PDFCosStream.java
10.2 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.internal.io.ByteReader
* com.adobe.internal.io.ByteWriter
* com.adobe.internal.io.ByteWriterFactory
* com.adobe.internal.io.ByteWriterFactory$Fixed
* com.adobe.internal.io.stream.IO
* com.adobe.internal.io.stream.InputByteStream
* com.adobe.internal.io.stream.OutputByteStream
* com.adobe.internal.io.stream.StreamManager
* com.adobe.internal.pdftoolkit.core.cos.CosArray
* com.adobe.internal.pdftoolkit.core.cos.CosDocument
* com.adobe.internal.pdftoolkit.core.cos.CosName
* com.adobe.internal.pdftoolkit.core.cos.CosNumeric
* com.adobe.internal.pdftoolkit.core.cos.CosObject
* com.adobe.internal.pdftoolkit.core.cos.CosStream
* com.adobe.internal.pdftoolkit.core.exceptions.PDFCosParseException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException
* com.adobe.internal.pdftoolkit.core.types.ASName
*/
package com.adobe.internal.pdftoolkit.pdf.document;
import com.adobe.internal.io.ByteReader;
import com.adobe.internal.io.ByteWriter;
import com.adobe.internal.io.ByteWriterFactory;
import com.adobe.internal.io.stream.IO;
import com.adobe.internal.io.stream.InputByteStream;
import com.adobe.internal.io.stream.OutputByteStream;
import com.adobe.internal.io.stream.StreamManager;
import com.adobe.internal.pdftoolkit.core.cos.CosArray;
import com.adobe.internal.pdftoolkit.core.cos.CosDocument;
import com.adobe.internal.pdftoolkit.core.cos.CosName;
import com.adobe.internal.pdftoolkit.core.cos.CosNumeric;
import com.adobe.internal.pdftoolkit.core.cos.CosObject;
import com.adobe.internal.pdftoolkit.core.cos.CosStream;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFCosParseException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidParameterException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosDictionary;
import com.adobe.internal.pdftoolkit.pdf.document.PDFCosObject;
import com.adobe.internal.pdftoolkit.pdf.document.PDFDocument;
import com.adobe.internal.pdftoolkit.pdf.filters.PDFFilter;
import com.adobe.internal.pdftoolkit.pdf.filters.PDFFilterList;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.Iterator;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public abstract class PDFCosStream
extends PDFCosDictionary {
public static final long STREAM_COMPRESSION_THRESHOLD = 15;
protected PDFCosStream(CosObject cosObject) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
super(cosObject);
if (!(cosObject instanceof CosStream)) {
this.removeFromCache(cosObject);
throw new PDFInvalidDocumentException("CosStream expected, found" + cosObject.getClass() + ". Object number of invalid cosObject:" + cosObject.getObjNum());
}
}
public long getLength() throws PDFCosParseException, PDFIOException, PDFSecurityException {
CosObject length = this.getCosStream().get(ASName.k_Length);
if (length instanceof CosNumeric) {
return length.intValue();
}
return 0;
}
public ASName getType() throws PDFCosParseException, PDFIOException, PDFSecurityException {
CosObject type = this.getCosStream().get(ASName.k_Type);
if (type instanceof CosName) {
return type.nameValue();
}
return null;
}
protected void setType(ASName type) throws PDFCosParseException, PDFIOException, PDFSecurityException {
CosName nameObj = this.getCosStream().getDocument().createCosName(type);
this.getCosStream().put(ASName.k_Type, (CosObject)nameObj);
}
public ASName getSubtype() throws PDFCosParseException, PDFIOException, PDFSecurityException {
CosObject type = this.getCosStream().get(ASName.k_Subtype);
if (type instanceof CosName) {
return type.nameValue();
}
return null;
}
protected void setSubtype(ASName subtype) throws PDFIOException, PDFSecurityException, PDFInvalidDocumentException, PDFInvalidParameterException {
CosName nameObj = this.getCosStream().getDocument().createCosName(subtype);
this.getCosStream().put(ASName.k_Subtype, (CosObject)nameObj);
}
public boolean hasInputFilters() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return this.getCosStream().getInputFiltersList() != null;
}
public PDFFilterList getInputFilters() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return PDFFilterList.getInstance((CosObject)this.getCosStream().getInputFiltersList());
}
public boolean hasOutputFilters() {
return this.getCosStream().getOutputFiltersList() != null;
}
public PDFFilterList getOutputFilters() throws PDFInvalidDocumentException {
return PDFFilterList.getInstance((CosObject)this.getCosStream().getOutputFiltersList());
}
public PDFFilterList procureOutputFilters() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFFilterList filterList = this.getOutputFilters();
if (filterList == null) {
filterList = this.getInputFilters();
}
if (filterList == null) {
filterList = PDFFilterList.newInstance(this.getPDFDocument());
}
return filterList;
}
public void setOutputFilters(PDFFilterList outputFilters) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
try {
this.getCosStream().setOutputFiltersList(outputFilters.getCosArray());
}
catch (IOException e) {
throw new PDFIOException((Throwable)e);
}
}
public void setOutputFilter(ASName filterName) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
PDFFilterList outputFilters = this.procureOutputFilters();
outputFilters.clear();
PDFFilter filter = PDFFilter.newInstance(this.getPDFDocument(), filterName, null);
outputFilters.add(filter);
this.setOutputFilters(outputFilters);
}
public void removeOutputFilters() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.hasOutputFilters() || this.hasInputFilters()) {
try {
this.getCosStream().setOutputFiltersList(PDFCosStream.newCosArray(this.getPDFDocument()));
}
catch (IOException e) {
throw new PDFIOException((Throwable)e);
}
}
}
public boolean getStreamData(OutputStream outStm) throws PDFCosParseException, PDFIOException, PDFSecurityException {
return this.getCosStream().copyStream((Object)outStm, false);
}
public void getStreamData(ByteWriter outStm) throws PDFCosParseException, PDFIOException, PDFSecurityException {
try {
OutputByteStream outputByteStream = this.getStreamManager().getOutputByteStream(outStm);
this.getCosStream().copyStream((Object)outputByteStream, false);
}
catch (IOException e) {
throw new PDFIOException((Throwable)e);
}
}
public void setStreamData(InputStream inStm) throws PDFCosParseException, PDFIOException, PDFSecurityException {
this.setStreamData(inStm, false);
}
public void setStreamData(InputStream inStm, boolean encoded) throws PDFCosParseException, PDFIOException, PDFSecurityException {
try {
OutputByteStream obs = this.getStreamManager().getOutputByteStreamClearDocument(ByteWriterFactory.Fixed.GROWABLE, -1);
IO.copy((InputStream)inStm, (OutputByteStream)obs);
InputByteStream ibs = obs.closeAndConvert();
obs = null;
if (encoded) {
this.getCosStream().newDataEncoded(ibs);
} else {
this.getCosStream().newDataDecoded(ibs);
}
ibs = null;
}
catch (IOException e) {
throw new PDFIOException((Throwable)e);
}
}
public void setStreamData(ByteReader inStm) throws PDFIOException, PDFCosParseException, PDFSecurityException {
this.setStreamData(inStm, false);
}
public void setStreamData(ByteReader inStm, boolean encoded) throws PDFIOException, PDFCosParseException, PDFSecurityException {
try {
InputByteStream byteStream = this.getStreamManager().getInputByteStream(inStm);
if (encoded) {
this.getCosStream().newDataEncoded(byteStream);
} else {
this.getCosStream().newDataDecoded(byteStream);
}
}
catch (IOException e) {
throw new PDFIOException((Throwable)e);
}
}
public static void setStreamLength(CosStream stream, int length) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
stream.put(ASName.k_Length, length);
}
public static void setStreamFilter(CosStream stream, PDFDocument pdfDoc, ArrayList<String> filters) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
ArrayList<CosName> nameList = new ArrayList<CosName>(filters.size());
Iterator<String> fNdx = filters.iterator();
while (fNdx.hasNext()) {
ASName filterName = ASName.create((String)fNdx.next());
nameList.add(PDFCosObject.newCosName(pdfDoc, filterName));
}
stream.put(ASName.k_Filter, (CosObject)PDFCosObject.newCosArray(pdfDoc, nameList));
}
public static void setStreamFilter(CosStream stream, String filter) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
stream.put(ASName.k_Filter, ASName.create((String)filter));
}
}