ContentReader.java
4.53 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.internal.pdftoolkit.core.cos.CosDictionary
* com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidContentException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFParseException
* com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException
* com.adobe.internal.pdftoolkit.core.types.ASName
*/
package com.adobe.internal.pdftoolkit.pdf.content;
import com.adobe.internal.pdftoolkit.core.cos.CosDictionary;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFIOException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidContentException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFInvalidDocumentException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFParseException;
import com.adobe.internal.pdftoolkit.core.exceptions.PDFSecurityException;
import com.adobe.internal.pdftoolkit.core.types.ASName;
import com.adobe.internal.pdftoolkit.pdf.content.Content;
import com.adobe.internal.pdftoolkit.pdf.content.ContentParser;
import com.adobe.internal.pdftoolkit.pdf.content.Instruction;
import com.adobe.internal.pdftoolkit.pdf.document.PDFContents;
import com.adobe.internal.pdftoolkit.pdf.document.PDFResources;
import java.io.IOException;
import java.util.HashSet;
import java.util.Set;
/*
* This class specifies class file version 49.0 but uses Java 6 signatures. Assumed Java 6.
*/
public class ContentReader {
private ContentParser parser;
private Instruction nextInstr;
private ContentReader(Content content) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosDictionary csMap = null;
PDFResources pdfResources = content.getResources();
if (pdfResources != null) {
csMap = pdfResources.getDictionaryDictionaryValue(ASName.k_ColorSpace);
}
this.parser = new ContentParser(content.getContents(), csMap);
}
private ContentReader(Content content, HashSet<ASName> operators) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
CosDictionary csMap = null;
PDFResources pdfResources = content.getResources();
if (pdfResources != null) {
csMap = pdfResources.getDictionaryDictionaryValue(ASName.k_ColorSpace);
}
this.parser = new ContentParser(content.getContents(), csMap, operators);
}
private ContentReader(ContentParser parser) {
this.parser = parser;
}
public static ContentReader newInstance(Content content) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
return new ContentReader(content);
}
public static ContentReader newInstance(Content content, HashSet<ASName> operators) throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
operators.add(ASName.k_ID);
return new ContentReader(content, operators);
}
public boolean hasNext() throws PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
if (this.nextInstr != null) {
return true;
}
try {
this.nextInstr = this.parser.nextInstruction();
return this.nextInstr != null;
}
catch (PDFParseException e) {
throw new PDFInvalidContentException((Throwable)e);
}
}
public Instruction next() {
Instruction returnInstr = this.nextInstr;
this.nextInstr = null;
return returnInstr;
}
public Instruction next(ASName scanOperator) throws PDFInvalidContentException, PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
while (this.hasNext()) {
Instruction instruction = this.next();
if (instruction.getOperator() != scanOperator) continue;
return instruction;
}
return null;
}
public Instruction next(Set scanOperators) throws PDFInvalidContentException, PDFInvalidDocumentException, PDFIOException, PDFSecurityException {
while (this.hasNext()) {
Instruction instruction = this.next();
if (!scanOperators.contains((Object)instruction.getOperator())) continue;
return instruction;
}
return null;
}
public ContentReader slice() throws PDFIOException {
return new ContentReader(this.parser.slice());
}
public void close() throws IOException {
this.parser.close();
}
}