Skip to content

Commit 6046d08

Browse files
committed
Update throws PdfException and throws IOException
1 parent c25d43c commit 6046d08

File tree

87 files changed

+1209
-1410
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

87 files changed

+1209
-1410
lines changed

basics/src/main/java/com/itextpdf/basics/codec/Base64.java

Lines changed: 564 additions & 515 deletions
Large diffs are not rendered by default.

basics/src/main/java/com/itextpdf/basics/codec/Jbig2SegmentReader.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import com.itextpdf.basics.source.RandomAccessFileOrArray;
44

55
import java.io.ByteArrayOutputStream;
6-
import java.io.IOException;
76
import java.util.Iterator;
87
import java.util.Map;
98
import java.util.Set;
@@ -20,7 +19,6 @@
2019
*
2120
* TODO: the indeterminate-segment-size value of dataLength, else?
2221
*
23-
* @since 2.1.5
2422
*/
2523

2624
public class Jbig2SegmentReader {
@@ -115,7 +113,7 @@ public Jbig2Page(int page, Jbig2SegmentReader sr) {
115113
* @throws java.io.IOException
116114
* @return a byte array
117115
*/
118-
public byte[] getData(boolean for_embedding) throws IOException {
116+
public byte[] getData(boolean for_embedding) throws java.io.IOException {
119117
ByteArrayOutputStream os = new ByteArrayOutputStream();
120118
for (Integer sn : segs.keySet()) {
121119
Jbig2Segment s = segs.get(sn);
@@ -154,7 +152,7 @@ public void addSegment(Jbig2Segment s) {
154152

155153
}
156154

157-
public Jbig2SegmentReader(RandomAccessFileOrArray ra) throws IOException {
155+
public Jbig2SegmentReader(RandomAccessFileOrArray ra) throws java.io.IOException {
158156
this.ra = ra;
159157
}
160158

@@ -164,7 +162,7 @@ public static byte[] copyByteArray(byte[] b) {
164162
return bc;
165163
}
166164

167-
public void read() throws IOException {
165+
public void read() throws java.io.IOException {
168166
if (this.read) {
169167
throw new IllegalStateException("already.attempted.a.read.on.this.jbig2.file");
170168
}
@@ -193,7 +191,7 @@ public void read() throws IOException {
193191
}
194192
}
195193

196-
void readSegment(Jbig2Segment s) throws IOException {
194+
void readSegment(Jbig2Segment s) throws java.io.IOException {
197195
int ptr = (int) ra.getPosition();
198196

199197
if (s.dataLength == 0xffffffffl) {
@@ -222,7 +220,7 @@ void readSegment(Jbig2Segment s) throws IOException {
222220
}
223221
}
224222

225-
Jbig2Segment readHeader() throws IOException {
223+
Jbig2Segment readHeader() throws java.io.IOException {
226224
int ptr = (int) ra.getPosition();
227225
// 7.2.1
228226
int segment_number = ra.readInt();
@@ -326,7 +324,7 @@ Jbig2Segment readHeader() throws IOException {
326324
return s;
327325
}
328326

329-
void readFileHeader() throws IOException {
327+
void readFileHeader() throws java.io.IOException {
330328
ra.seek(0);
331329
byte[] idstring = new byte[8];
332330
ra.read(idstring);
@@ -383,7 +381,7 @@ public byte[] getGlobal(boolean for_embedding) {
383381
os.write(s.data);
384382
}
385383
os.close();
386-
} catch (IOException e) {
384+
} catch (java.io.IOException e) {
387385
e.printStackTrace();
388386
}
389387
if (os.size() <= 0) {

basics/src/main/java/com/itextpdf/basics/codec/TIFFDirectory.java

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -45,11 +45,9 @@
4545
*/
4646
package com.itextpdf.basics.codec;
4747

48-
import com.itextpdf.basics.PdfException;
4948
import com.itextpdf.basics.source.RandomAccessFileOrArray;
5049

5150
import java.io.EOFException;
52-
import java.io.IOException;
5351
import java.io.Serializable;
5452
import java.util.ArrayList;
5553
import java.util.HashMap;
@@ -133,7 +131,7 @@ private static boolean isValidEndianTag(int endian) {
133131
* @param directory the index of the directory to read.
134132
*/
135133
public TIFFDirectory(RandomAccessFileOrArray stream, int directory)
136-
throws IOException {
134+
throws java.io.IOException {
137135

138136
long global_save_offset = stream.getPosition();
139137
long ifd_offset;
@@ -142,21 +140,21 @@ public TIFFDirectory(RandomAccessFileOrArray stream, int directory)
142140
stream.seek(0L);
143141
int endian = stream.readUnsignedShort();
144142
if (!isValidEndianTag(endian)) {
145-
throw new PdfException(PdfException.BadEndiannessTagNot0x4949Or0x4d4d);
143+
throw new com.itextpdf.basics.PdfException(com.itextpdf.basics.PdfException.BadEndiannessTagNot0x4949Or0x4d4d);
146144
}
147145
isBigEndian = endian == 0x4d4d;
148146

149147
int magic = readUnsignedShort(stream);
150148
if (magic != 42) {
151-
throw new PdfException(PdfException.BadMagicNumberShouldBe42);
149+
throw new com.itextpdf.basics.PdfException(com.itextpdf.basics.PdfException.BadMagicNumberShouldBe42);
152150
}
153151

154152
// Get the initial ifd offset as an unsigned int (using a long)
155153
ifd_offset = readUnsignedInt(stream);
156154

157155
for (int i = 0; i < directory; i++) {
158156
if (ifd_offset == 0L) {
159-
throw new PdfException(PdfException.DirectoryNumberTooLarge);
157+
throw new com.itextpdf.basics.PdfException(com.itextpdf.basics.PdfException.DirectoryNumberTooLarge);
160158
}
161159

162160
stream.seek(ifd_offset);
@@ -185,13 +183,13 @@ public TIFFDirectory(RandomAccessFileOrArray stream, int directory)
185183
* at the current offset.
186184
*/
187185
public TIFFDirectory(RandomAccessFileOrArray stream, long ifd_offset, int directory)
188-
throws IOException {
186+
throws java.io.IOException {
189187

190188
long global_save_offset = stream.getPosition();
191189
stream.seek(0L);
192190
int endian = stream.readUnsignedShort();
193191
if (!isValidEndianTag(endian)) {
194-
throw new PdfException(PdfException.BadEndiannessTagNot0x4949Or0x4d4d);
192+
throw new com.itextpdf.basics.PdfException(com.itextpdf.basics.PdfException.BadEndiannessTagNot0x4949Or0x4d4d);
195193
}
196194
isBigEndian = endian == 0x4d4d;
197195

@@ -237,7 +235,7 @@ public TIFFDirectory(RandomAccessFileOrArray stream, long ifd_offset, int direct
237235
8 // 12 = double
238236
};
239237

240-
private void initialize(RandomAccessFileOrArray stream) throws IOException {
238+
private void initialize(RandomAccessFileOrArray stream) throws java.io.IOException {
241239
long nextTagOffset = 0L;
242240
long maxOffset = stream.length();
243241
int i, j;
@@ -538,7 +536,7 @@ public double getFieldAsDouble(int tag) {
538536
// Methods to read primitive data types from the stream
539537

540538
private short readShort(RandomAccessFileOrArray stream)
541-
throws IOException {
539+
throws java.io.IOException {
542540
if (isBigEndian) {
543541
return stream.readShort();
544542
} else {
@@ -547,7 +545,7 @@ private short readShort(RandomAccessFileOrArray stream)
547545
}
548546

549547
private int readUnsignedShort(RandomAccessFileOrArray stream)
550-
throws IOException {
548+
throws java.io.IOException {
551549
if (isBigEndian) {
552550
return stream.readUnsignedShort();
553551
} else {
@@ -556,7 +554,7 @@ private int readUnsignedShort(RandomAccessFileOrArray stream)
556554
}
557555

558556
private int readInt(RandomAccessFileOrArray stream)
559-
throws IOException {
557+
throws java.io.IOException {
560558
if (isBigEndian) {
561559
return stream.readInt();
562560
} else {
@@ -565,7 +563,7 @@ private int readInt(RandomAccessFileOrArray stream)
565563
}
566564

567565
private long readUnsignedInt(RandomAccessFileOrArray stream)
568-
throws IOException {
566+
throws java.io.IOException {
569567
if (isBigEndian) {
570568
return stream.readUnsignedInt();
571569
} else {
@@ -574,7 +572,7 @@ private long readUnsignedInt(RandomAccessFileOrArray stream)
574572
}
575573

576574
private long readLong(RandomAccessFileOrArray stream)
577-
throws IOException {
575+
throws java.io.IOException {
578576
if (isBigEndian) {
579577
return stream.readLong();
580578
} else {
@@ -583,7 +581,7 @@ private long readLong(RandomAccessFileOrArray stream)
583581
}
584582

585583
private float readFloat(RandomAccessFileOrArray stream)
586-
throws IOException {
584+
throws java.io.IOException {
587585
if (isBigEndian) {
588586
return stream.readFloat();
589587
} else {
@@ -592,7 +590,7 @@ private float readFloat(RandomAccessFileOrArray stream)
592590
}
593591

594592
private double readDouble(RandomAccessFileOrArray stream)
595-
throws IOException {
593+
throws java.io.IOException {
596594
if (isBigEndian) {
597595
return stream.readDouble();
598596
} else {
@@ -602,7 +600,7 @@ private double readDouble(RandomAccessFileOrArray stream)
602600

603601
private static int readUnsignedShort(RandomAccessFileOrArray stream,
604602
boolean isBigEndian)
605-
throws IOException {
603+
throws java.io.IOException {
606604
if (isBigEndian) {
607605
return stream.readUnsignedShort();
608606
} else {
@@ -612,7 +610,7 @@ private static int readUnsignedShort(RandomAccessFileOrArray stream,
612610

613611
private static long readUnsignedInt(RandomAccessFileOrArray stream,
614612
boolean isBigEndian)
615-
throws IOException {
613+
throws java.io.IOException {
616614
if (isBigEndian) {
617615
return stream.readUnsignedInt();
618616
} else {
@@ -627,18 +625,18 @@ private static long readUnsignedInt(RandomAccessFileOrArray stream,
627625
* given TIFF file, represented by a <code>SeekableStream</code>.
628626
*/
629627
public static int getNumDirectories(RandomAccessFileOrArray stream)
630-
throws IOException {
628+
throws java.io.IOException {
631629
long pointer = stream.getPosition(); // Save stream pointer
632630

633631
stream.seek(0L);
634632
int endian = stream.readUnsignedShort();
635633
if (!isValidEndianTag(endian)) {
636-
throw new PdfException(PdfException.BadEndiannessTagNot0x4949Or0x4d4d);
634+
throw new com.itextpdf.basics.PdfException(com.itextpdf.basics.PdfException.BadEndiannessTagNot0x4949Or0x4d4d);
637635
}
638636
boolean isBigEndian = endian == 0x4d4d;
639637
int magic = readUnsignedShort(stream, isBigEndian);
640638
if (magic != 42) {
641-
throw new PdfException(PdfException.BadMagicNumberShouldBe42);
639+
throw new com.itextpdf.basics.PdfException(com.itextpdf.basics.PdfException.BadMagicNumberShouldBe42);
642640
}
643641

644642
stream.seek(4L);

basics/src/main/java/com/itextpdf/basics/codec/TIFFFaxDecoder.java

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,6 @@
4545
*/
4646
package com.itextpdf.basics.codec;
4747

48-
import com.itextpdf.basics.PdfException;
49-
5048
/**
5149
* Class that can decode TIFF files.
5250
*/
@@ -656,9 +654,9 @@ public void decodeNextScanline(byte[] buffer, int lineOffset, int bitOffset) {
656654

657655
updatePointer(4 - bits);
658656
} else if (bits == 0) { // ERROR
659-
throw new PdfException(PdfException.InvalidCodeEncountered);
657+
throw new com.itextpdf.basics.PdfException(com.itextpdf.basics.PdfException.InvalidCodeEncountered);
660658
} else if (bits == 15) { // EOL
661-
throw new PdfException(PdfException.EolCodeWordEncounteredInWhiteRun);
659+
throw new com.itextpdf.basics.PdfException(com.itextpdf.basics.PdfException.EolCodeWordEncounteredInWhiteRun);
662660
} else {
663661
// 11 bits - 0000 0111 1111 1111 = 0x07ff
664662
code = (entry >>> 5) & 0x07ff;
@@ -713,7 +711,7 @@ public void decodeNextScanline(byte[] buffer, int lineOffset, int bitOffset) {
713711
updatePointer(4 - bits);
714712
} else if (bits == 15) {
715713
// EOL code
716-
throw new PdfException(PdfException.EolCodeWordEncounteredInWhiteRun);
714+
throw new com.itextpdf.basics.PdfException(com.itextpdf.basics.PdfException.EolCodeWordEncounteredInWhiteRun);
717715
} else {
718716
setToBlack(buffer, lineOffset, bitOffset, code);
719717
bitOffset += code;
@@ -790,7 +788,7 @@ public void decode2D(byte[] buffer, byte compData[], int startX, int height, lon
790788

791789
// The data must start with an EOL code
792790
if (readEOL(true) != 1) {
793-
throw new PdfException(PdfException.FirstScanlineMustBe1dEncoded);
791+
throw new com.itextpdf.basics.PdfException(com.itextpdf.basics.PdfException.FirstScanlineMustBe1dEncoded);
794792
}
795793

796794
int lineOffset = 0;
@@ -892,7 +890,7 @@ public void decode2D(byte[] buffer, byte compData[], int startX, int height, lon
892890

893891
updatePointer(7 - bits);
894892
} else {
895-
throw new PdfException(PdfException.InvalidCodeEncounteredWhileDecoding2dGroup3CompressedData);
893+
throw new com.itextpdf.basics.PdfException(com.itextpdf.basics.PdfException.InvalidCodeEncounteredWhileDecoding2dGroup3CompressedData);
896894
}
897895
}
898896

@@ -1040,7 +1038,7 @@ public void decodeT6(byte[] buffer,
10401038
updatePointer(7 - bits);
10411039
} else if (code == 11) {
10421040
if (nextLesserThan8Bits(3) != 7) {
1043-
throw new PdfException(PdfException.InvalidCodeEncounteredWhileDecoding2dGroup4CompressedData);
1041+
throw new com.itextpdf.basics.PdfException(com.itextpdf.basics.PdfException.InvalidCodeEncounteredWhileDecoding2dGroup4CompressedData);
10441042
}
10451043

10461044
int zeros = 0;
@@ -1193,12 +1191,12 @@ private int decodeWhiteCodeWord() {
11931191
runLength += code;
11941192
updatePointer(4 - bits);
11951193
} else if (bits == 0) { // ERROR
1196-
throw new PdfException(PdfException.InvalidCodeEncountered);
1194+
throw new com.itextpdf.basics.PdfException(com.itextpdf.basics.PdfException.InvalidCodeEncountered);
11971195
} else if (bits == 15) { // EOL
11981196
if (runLength == 0) {
11991197
isWhite = false;
12001198
} else {
1201-
throw new PdfException(PdfException.EolCodeWordEncounteredInWhiteRun);
1199+
throw new com.itextpdf.basics.PdfException(com.itextpdf.basics.PdfException.EolCodeWordEncounteredInWhiteRun);
12021200
}
12031201
} else {
12041202
// 11 bits - 0000 0111 1111 1111 = 0x07ff
@@ -1250,7 +1248,7 @@ private int decodeBlackCodeWord() {
12501248
updatePointer(4 - bits);
12511249
} else if (bits == 15) {
12521250
// EOL code
1253-
throw new PdfException(PdfException.EolCodeWordEncounteredInBlackRun);
1251+
throw new com.itextpdf.basics.PdfException(com.itextpdf.basics.PdfException.EolCodeWordEncounteredInBlackRun);
12541252
} else {
12551253
runLength += code;
12561254
updatePointer(9 - bits);
@@ -1297,7 +1295,7 @@ private int readEOL(boolean isFirstEOL) {
12971295
}
12981296
}
12991297
if (next12Bits != 1) {
1300-
throw new PdfException(PdfException.ScanlineMustBeginWithEolCodeWord);
1298+
throw new com.itextpdf.basics.PdfException(com.itextpdf.basics.PdfException.ScanlineMustBeginWithEolCodeWord);
13011299
}
13021300
} else if (fillBits == 1) {
13031301

@@ -1308,7 +1306,7 @@ private int readEOL(boolean isFirstEOL) {
13081306
int bitsLeft = 8 - bitPointer;
13091307

13101308
if (nextNBits(bitsLeft) != 0) {
1311-
throw new PdfException(PdfException.AllFillBitsPrecedingEolCodeMustBe0);
1309+
throw new com.itextpdf.basics.PdfException(com.itextpdf.basics.PdfException.AllFillBitsPrecedingEolCodeMustBe0);
13121310
}
13131311

13141312
// If the number of bitsLeft is less than 8, then to have a 12
@@ -1317,7 +1315,7 @@ private int readEOL(boolean isFirstEOL) {
13171315
// that.
13181316
if (bitsLeft < 4) {
13191317
if (nextNBits(8) != 0) {
1320-
throw new PdfException(PdfException.AllFillBitsPrecedingEolCodeMustBe0);
1318+
throw new com.itextpdf.basics.PdfException(com.itextpdf.basics.PdfException.AllFillBitsPrecedingEolCodeMustBe0);
13211319
}
13221320
}
13231321

@@ -1328,7 +1326,7 @@ private int readEOL(boolean isFirstEOL) {
13281326
while ((n = nextNBits(8)) != 1) {
13291327
// If not all zeros
13301328
if (n != 0) {
1331-
throw new PdfException(PdfException.AllFillBitsPrecedingEolCodeMustBe0);
1329+
throw new com.itextpdf.basics.PdfException(com.itextpdf.basics.PdfException.AllFillBitsPrecedingEolCodeMustBe0);
13321330
}
13331331
}
13341332
}
@@ -1405,7 +1403,7 @@ private int nextNBits(int bitsToGet) {
14051403
next2next = flipTable[data[bp + 2] & 0xff];
14061404
}
14071405
} else {
1408-
throw new PdfException(PdfException.TiffFillOrderTagMustBeEither1Or2);
1406+
throw new com.itextpdf.basics.PdfException(com.itextpdf.basics.PdfException.TiffFillOrderTagMustBeEither1Or2);
14091407
}
14101408

14111409
int bitsLeft = 8 - bitPointer;
@@ -1465,7 +1463,7 @@ private int nextLesserThan8Bits(int bitsToGet) {
14651463
}
14661464
}
14671465
} else {
1468-
throw new PdfException(PdfException.TiffFillOrderTagMustBeEither1Or2);
1466+
throw new com.itextpdf.basics.PdfException(com.itextpdf.basics.PdfException.TiffFillOrderTagMustBeEither1Or2);
14691467
}
14701468

14711469
int bitsLeft = 8 - bitPointer;

0 commit comments

Comments
 (0)