Skip to content

Commit 0c18dc0

Browse files
author
Andrei Stryhelski
committed
Update style of exceptions, constants
DEVSIX-7373
1 parent 4022d69 commit 0c18dc0

File tree

73 files changed

+531
-473
lines changed

Some content is hidden

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

73 files changed

+531
-473
lines changed

barcodes/src/main/java/com/itextpdf/barcodes/Barcode128.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.barcodes;
2424

25-
import com.itextpdf.barcodes.exceptions.BarcodeExceptionMessageConstant;
25+
import com.itextpdf.barcodes.exceptions.BarcodesExceptionMessageConstant;
2626
import com.itextpdf.kernel.exceptions.PdfException;
2727
import com.itextpdf.kernel.colors.Color;
2828
import com.itextpdf.kernel.font.PdfFont;
@@ -332,7 +332,7 @@ public static String getRawText(String text, boolean ucc, Barcode128CodeSet code
332332
for (int k = 0; k < tLen; ++k) {
333333
c = text.charAt(k);
334334
if (c > 127 && c != FNC1)
335-
throw new PdfException(BarcodeExceptionMessageConstant.THERE_ARE_ILLEGAL_CHARACTERS_FOR_BARCODE_128);
335+
throw new PdfException(BarcodesExceptionMessageConstant.THERE_ARE_ILLEGAL_CHARACTERS_FOR_BARCODE_128);
336336
}
337337
c = text.charAt(0);
338338
char currentCode = getStartSymbol(codeSet);
@@ -363,7 +363,7 @@ public static String getRawText(String text, boolean ucc, Barcode128CodeSet code
363363
++index;
364364
}
365365
if (codeSet != Barcode128CodeSet.AUTO && currentCode != getStartSymbol(codeSet))
366-
throw new PdfException(BarcodeExceptionMessageConstant.THERE_ARE_ILLEGAL_CHARACTERS_FOR_BARCODE_128);
366+
throw new PdfException(BarcodesExceptionMessageConstant.THERE_ARE_ILLEGAL_CHARACTERS_FOR_BARCODE_128);
367367
while (index < tLen) {
368368
switch (currentCode) {
369369
case START_A: {
@@ -432,7 +432,7 @@ else if (c < ' ') {
432432
break;
433433
}
434434
if (codeSet != Barcode128CodeSet.AUTO && currentCode != getStartSymbol(codeSet))
435-
throw new PdfException(BarcodeExceptionMessageConstant.THERE_ARE_ILLEGAL_CHARACTERS_FOR_BARCODE_128);
435+
throw new PdfException(BarcodesExceptionMessageConstant.THERE_ARE_ILLEGAL_CHARACTERS_FOR_BARCODE_128);
436436
}
437437
return out;
438438
}

barcodes/src/main/java/com/itextpdf/barcodes/BarcodeCodabar.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.barcodes;
2424

25-
import com.itextpdf.barcodes.exceptions.BarcodeExceptionMessageConstant;
25+
import com.itextpdf.barcodes.exceptions.BarcodesExceptionMessageConstant;
2626
import com.itextpdf.kernel.font.PdfFont;
2727
import com.itextpdf.kernel.geom.Rectangle;
2828
import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
@@ -147,22 +147,22 @@ public static byte[] getBarsCodabar(String text) {
147147
int len = text.length();
148148
if (len < 2) {
149149
throw new IllegalArgumentException(
150-
BarcodeExceptionMessageConstant.CODABAR_MUST_HAVE_AT_LEAST_START_AND_STOP_CHARACTER);
150+
BarcodesExceptionMessageConstant.CODABAR_MUST_HAVE_AT_LEAST_START_AND_STOP_CHARACTER);
151151
}
152152
if (CHARS.indexOf(text.charAt(0)) < START_STOP_IDX || CHARS.indexOf(text.charAt(len - 1)) < START_STOP_IDX) {
153153
throw new IllegalArgumentException(
154-
BarcodeExceptionMessageConstant.CODABAR_MUST_HAVE_ONE_ABCD_AS_START_STOP_CHARACTER);
154+
BarcodesExceptionMessageConstant.CODABAR_MUST_HAVE_ONE_ABCD_AS_START_STOP_CHARACTER);
155155
}
156156
byte[] bars = new byte[text.length() * 8 - 1];
157157
for (int k = 0; k < len; ++k) {
158158
int idx = CHARS.indexOf(text.charAt(k));
159159
if (idx >= START_STOP_IDX && k > 0 && k < len - 1) {
160-
throw new IllegalArgumentException(BarcodeExceptionMessageConstant.
160+
throw new IllegalArgumentException(BarcodesExceptionMessageConstant.
161161
IN_CODABAR_START_STOP_CHARACTERS_ARE_ONLY_ALLOWED_AT_THE_EXTREMES);
162162
}
163163
if (idx < 0) {
164164
throw new IllegalArgumentException(
165-
BarcodeExceptionMessageConstant.ILLEGAL_CHARACTER_IN_CODABAR_BARCODE);
165+
BarcodesExceptionMessageConstant.ILLEGAL_CHARACTER_IN_CODABAR_BARCODE);
166166
}
167167
System.arraycopy(BARS[idx], 0, bars, k * 8, 7);
168168
}

barcodes/src/main/java/com/itextpdf/barcodes/BarcodeEANSUPP.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.barcodes;
2424

25-
import com.itextpdf.barcodes.exceptions.BarcodeExceptionMessageConstant;
25+
import com.itextpdf.barcodes.exceptions.BarcodesExceptionMessageConstant;
2626
import com.itextpdf.io.font.FontProgram;
2727
import com.itextpdf.kernel.geom.Rectangle;
2828
import com.itextpdf.kernel.pdf.canvas.PdfCanvas;
@@ -136,7 +136,7 @@ public Rectangle placeBarcode(PdfCanvas canvas, Color barColor, Color textColor)
136136
*/
137137
@Override
138138
public java.awt.Image createAwtImage(java.awt.Color foreground, java.awt.Color background) {
139-
throw new UnsupportedOperationException(BarcodeExceptionMessageConstant.TWO_BARCODE_MUST_BE_EXTERNALLY);
139+
throw new UnsupportedOperationException(BarcodesExceptionMessageConstant.TWO_BARCODE_MUST_BE_EXTERNALLY);
140140
}
141141
// Android-Conversion-Skip-Block-End
142142
}

barcodes/src/main/java/com/itextpdf/barcodes/BarcodeInter25.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.barcodes;
2424

25-
import com.itextpdf.barcodes.exceptions.BarcodeExceptionMessageConstant;
25+
import com.itextpdf.barcodes.exceptions.BarcodesExceptionMessageConstant;
2626
import com.itextpdf.kernel.exceptions.PdfException;
2727
import com.itextpdf.kernel.font.PdfFont;
2828
import com.itextpdf.kernel.geom.Rectangle;
@@ -140,7 +140,7 @@ public static char getChecksum(String text) {
140140
public static byte[] getBarsInter25(String text) {
141141
text = keepNumbers(text);
142142
if ((text.length() & 1) != 0) {
143-
throw new PdfException(BarcodeExceptionMessageConstant.TEXT_MUST_BE_EVEN);
143+
throw new PdfException(BarcodesExceptionMessageConstant.TEXT_MUST_BE_EVEN);
144144
}
145145
byte[] bars = new byte[text.length() * 5 + 7];
146146
int pb = 0;

barcodes/src/main/java/com/itextpdf/barcodes/BarcodePDF417.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.barcodes;
2424

25-
import com.itextpdf.barcodes.exceptions.BarcodeExceptionMessageConstant;
25+
import com.itextpdf.barcodes.exceptions.BarcodesExceptionMessageConstant;
2626
import com.itextpdf.kernel.exceptions.PdfException;
2727
import com.itextpdf.io.font.PdfEncodings;
2828
import com.itextpdf.kernel.geom.Rectangle;
@@ -706,13 +706,13 @@ public void paintCode() {
706706
int maxErr, lenErr, tot, pad;
707707
if ((options & PDF417_USE_RAW_CODEWORDS) != 0) {
708708
if (lenCodewords > MAX_DATA_CODEWORDS || lenCodewords < 1 || lenCodewords != codewords[0]) {
709-
throw new PdfException(BarcodeExceptionMessageConstant.INVALID_CODEWORD_SIZE);
709+
throw new PdfException(BarcodesExceptionMessageConstant.INVALID_CODEWORD_SIZE);
710710
}
711711
} else {
712712
if (code == null)
713-
throw new PdfException(BarcodeExceptionMessageConstant.TEXT_CANNOT_BE_NULL);
713+
throw new PdfException(BarcodesExceptionMessageConstant.TEXT_CANNOT_BE_NULL);
714714
if (code.length > ABSOLUTE_MAX_TEXT_SIZE) {
715-
throw new PdfException(BarcodeExceptionMessageConstant.TEXT_IS_TOO_BIG);
715+
throw new PdfException(BarcodesExceptionMessageConstant.TEXT_IS_TOO_BIG);
716716
}
717717
segmentList = new SegmentList();
718718
breakString();
@@ -1298,7 +1298,7 @@ void byteCompaction(int start, int length) {
12981298
int k, j;
12991299
int size = length / 6 * 5 + length % 6;
13001300
if (size + cwPtr > MAX_DATA_CODEWORDS) {
1301-
throw new PdfException(BarcodeExceptionMessageConstant.TEXT_IS_TOO_BIG);
1301+
throw new PdfException(BarcodesExceptionMessageConstant.TEXT_IS_TOO_BIG);
13021302
}
13031303
length += start;
13041304
for (k = start; k < length; k += 6) {
@@ -1483,7 +1483,7 @@ private void numberCompaction(byte[] input, int start, int length) {
14831483
else
14841484
size = full + size / 3 + 1;
14851485
if (size + cwPtr > MAX_DATA_CODEWORDS) {
1486-
throw new PdfException(BarcodeExceptionMessageConstant.TEXT_IS_TOO_BIG);
1486+
throw new PdfException(BarcodesExceptionMessageConstant.TEXT_IS_TOO_BIG);
14871487
}
14881488
length += start;
14891489
for (k = start; k < length; k += 44) {
@@ -1494,13 +1494,13 @@ private void numberCompaction(byte[] input, int start, int length) {
14941494

14951495
private void macroCodes() {
14961496
if (macroSegmentId < 0) {
1497-
throw new PdfException(BarcodeExceptionMessageConstant.MACRO_SEGMENT_ID_MUST_BE_GT_OR_EQ_ZERO);
1497+
throw new PdfException(BarcodesExceptionMessageConstant.MACRO_SEGMENT_ID_MUST_BE_GT_OR_EQ_ZERO);
14981498
}
14991499
if (macroSegmentId >= macroSegmentCount) {
1500-
throw new PdfException(BarcodeExceptionMessageConstant.MACRO_SEGMENT_ID_MUST_BE_LT_MACRO_SEGMENT_COUNT);
1500+
throw new PdfException(BarcodesExceptionMessageConstant.MACRO_SEGMENT_ID_MUST_BE_LT_MACRO_SEGMENT_COUNT);
15011501
}
15021502
if (macroSegmentCount < 1) {
1503-
throw new PdfException(BarcodeExceptionMessageConstant.MACRO_SEGMENT_ID_MUST_BE_GT_ZERO);
1503+
throw new PdfException(BarcodesExceptionMessageConstant.MACRO_SEGMENT_ID_MUST_BE_GT_ZERO);
15041504
}
15051505

15061506
macroIndex = cwPtr;
@@ -1653,7 +1653,7 @@ private void textCompaction(byte[] input, int start, int length) {
16531653
dest[ptr++] = PS;
16541654
size = (ptr + fullBytes) / 2;
16551655
if (size + cwPtr > MAX_DATA_CODEWORDS) {
1656-
throw new PdfException(BarcodeExceptionMessageConstant.TEXT_IS_TOO_BIG);
1656+
throw new PdfException(BarcodesExceptionMessageConstant.TEXT_IS_TOO_BIG);
16571657
}
16581658
length = ptr;
16591659
ptr = 0;

barcodes/src/main/java/com/itextpdf/barcodes/exceptions/BarcodeExceptionMessageConstant.java renamed to barcodes/src/main/java/com/itextpdf/barcodes/exceptions/BarcodesExceptionMessageConstant.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ This file is part of the iText (R) project.
2525
/**
2626
* Class that bundles all the error message templates as constants.
2727
*/
28-
public final class BarcodeExceptionMessageConstant {
28+
public final class BarcodesExceptionMessageConstant {
2929
public static final String CODABAR_MUST_HAVE_AT_LEAST_START_AND_STOP_CHARACTER = "Codabar must have at least start "
3030
+ "and stop character.";
3131
public static final String CODABAR_MUST_HAVE_ONE_ABCD_AS_START_STOP_CHARACTER = "Codabar must have one of 'ABCD' "
@@ -45,5 +45,5 @@ public final class BarcodeExceptionMessageConstant {
4545
public static final String THERE_ARE_ILLEGAL_CHARACTERS_FOR_BARCODE_128 = "There are illegal characters for "
4646
+ "barcode 128 in {0}.";
4747

48-
private BarcodeExceptionMessageConstant(){}
48+
private BarcodesExceptionMessageConstant(){}
4949
}

barcodes/src/test/java/com/itextpdf/barcodes/BarcodeCodabarTest.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ This file is part of the iText (R) project.
2323
package com.itextpdf.barcodes;
2424

2525

26-
import com.itextpdf.barcodes.exceptions.BarcodeExceptionMessageConstant;
26+
import com.itextpdf.barcodes.exceptions.BarcodesExceptionMessageConstant;
2727
import com.itextpdf.kernel.exceptions.PdfException;
2828
import com.itextpdf.kernel.pdf.PdfDocument;
2929
import com.itextpdf.kernel.pdf.PdfPage;
@@ -79,7 +79,7 @@ public void barcodeHasNoAbcdAsStartCharacterTest() {
7979
BarcodeCodabar codabar = new BarcodeCodabar(pdfDocument);
8080
Exception exception = Assert.assertThrows(IllegalArgumentException.class,
8181
() -> codabar.getBarsCodabar("qbcd"));
82-
Assert.assertEquals(BarcodeExceptionMessageConstant.CODABAR_MUST_HAVE_ONE_ABCD_AS_START_STOP_CHARACTER,
82+
Assert.assertEquals(BarcodesExceptionMessageConstant.CODABAR_MUST_HAVE_ONE_ABCD_AS_START_STOP_CHARACTER,
8383
exception.getMessage());
8484
}
8585

@@ -89,7 +89,7 @@ public void barcodeHasNoAbcdAsStopCharacterTest() {
8989
BarcodeCodabar codabar = new BarcodeCodabar(pdfDocument);
9090
Exception exception = Assert.assertThrows(IllegalArgumentException.class,
9191
() -> codabar.getBarsCodabar("abcf"));
92-
Assert.assertEquals(BarcodeExceptionMessageConstant.CODABAR_MUST_HAVE_ONE_ABCD_AS_START_STOP_CHARACTER,
92+
Assert.assertEquals(BarcodesExceptionMessageConstant.CODABAR_MUST_HAVE_ONE_ABCD_AS_START_STOP_CHARACTER,
9393
exception.getMessage());
9494
}
9595

@@ -99,7 +99,7 @@ public void barcodeHasNoAbcdAsStartAndStopCharacterTest() {
9999
BarcodeCodabar codabar = new BarcodeCodabar(pdfDocument);
100100
Exception exception = Assert.assertThrows(IllegalArgumentException.class,
101101
() -> codabar.getBarsCodabar("qbcq"));
102-
Assert.assertEquals(BarcodeExceptionMessageConstant.CODABAR_MUST_HAVE_ONE_ABCD_AS_START_STOP_CHARACTER,
102+
Assert.assertEquals(BarcodesExceptionMessageConstant.CODABAR_MUST_HAVE_ONE_ABCD_AS_START_STOP_CHARACTER,
103103
exception.getMessage());
104104
}
105105

@@ -109,7 +109,7 @@ public void barcodeHasNoStartAndStopCharacterTest() {
109109
BarcodeCodabar codabar = new BarcodeCodabar(pdfDocument);
110110
Exception exception = Assert.assertThrows(IllegalArgumentException.class,
111111
() -> codabar.getBarsCodabar(""));
112-
Assert.assertEquals(BarcodeExceptionMessageConstant.CODABAR_MUST_HAVE_AT_LEAST_START_AND_STOP_CHARACTER,
112+
Assert.assertEquals(BarcodesExceptionMessageConstant.CODABAR_MUST_HAVE_AT_LEAST_START_AND_STOP_CHARACTER,
113113
exception.getMessage());
114114
}
115115
}

barcodes/src/test/java/com/itextpdf/barcodes/BarcodePDF417Test.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ This file is part of the iText (R) project.
2222
*/
2323
package com.itextpdf.barcodes;
2424

25-
import com.itextpdf.barcodes.exceptions.BarcodeExceptionMessageConstant;
25+
import com.itextpdf.barcodes.exceptions.BarcodesExceptionMessageConstant;
2626
import com.itextpdf.io.codec.CCITTG4Encoder;
2727
import com.itextpdf.io.image.ImageData;
2828
import com.itextpdf.io.image.ImageDataFactory;
@@ -445,7 +445,7 @@ public void lenCodewordsIsNotEnoughTest() {
445445
barcodePDF417.setOptions(BarcodePDF417.PDF417_USE_RAW_CODEWORDS);
446446
Exception exception = Assert.assertThrows(PdfException.class,
447447
() -> barcodePDF417.paintCode());
448-
Assert.assertEquals(BarcodeExceptionMessageConstant.INVALID_CODEWORD_SIZE, exception.getMessage());
448+
Assert.assertEquals(BarcodesExceptionMessageConstant.INVALID_CODEWORD_SIZE, exception.getMessage());
449449
}
450450

451451
@Test
@@ -456,7 +456,7 @@ public void lenCodewordsIsTooSmallTest() {
456456
barcodePDF417.setLenCodewords(0);
457457
Exception exception = Assert.assertThrows(PdfException.class,
458458
() -> barcodePDF417.paintCode());
459-
Assert.assertEquals(BarcodeExceptionMessageConstant.INVALID_CODEWORD_SIZE, exception.getMessage());
459+
Assert.assertEquals(BarcodesExceptionMessageConstant.INVALID_CODEWORD_SIZE, exception.getMessage());
460460
}
461461

462462
@Test
@@ -467,7 +467,7 @@ public void lenCodewordsMoreThanMaxDataCodewordsTest() {
467467
barcodePDF417.setLenCodewords(927);
468468
Exception exception = Assert.assertThrows(PdfException.class,
469469
() -> barcodePDF417.paintCode());
470-
Assert.assertEquals(BarcodeExceptionMessageConstant.INVALID_CODEWORD_SIZE, exception.getMessage());
470+
Assert.assertEquals(BarcodesExceptionMessageConstant.INVALID_CODEWORD_SIZE, exception.getMessage());
471471
}
472472

473473
@Test

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
package com.itextpdf.io.codec;
4747

4848
import com.itextpdf.io.exceptions.IOException;
49+
import com.itextpdf.io.exceptions.IoExceptionMessageConstant;
4950
import com.itextpdf.io.source.RandomAccessFileOrArray;
5051

5152
import java.io.EOFException;
@@ -139,21 +140,21 @@ public TIFFDirectory(RandomAccessFileOrArray stream, int directory)
139140
stream.seek(0L);
140141
int endian = stream.readUnsignedShort();
141142
if (!isValidEndianTag(endian)) {
142-
throw new IOException(IOException.BadEndiannessTag0x4949Or0x4d4d);
143+
throw new IOException(IoExceptionMessageConstant.BAD_ENDIANNESS_TAG_0X4949_OR_0X4D4D);
143144
}
144145
isBigEndian = endian == 0x4d4d;
145146

146147
int magic = readUnsignedShort(stream);
147148
if (magic != 42) {
148-
throw new IOException(IOException.BadMagicNumberShouldBe42);
149+
throw new IOException(IoExceptionMessageConstant.BAD_MAGIC_NUMBER_SHOULD_BE_42);
149150
}
150151

151152
// Get the initial ifd offset as an unsigned int (using a long)
152153
ifd_offset = readUnsignedInt(stream);
153154

154155
for (int i = 0; i < directory; i++) {
155156
if (ifd_offset == 0L) {
156-
throw new IOException(IOException.DirectoryNumberIsTooLarge);
157+
throw new IOException(IoExceptionMessageConstant.DIRECTORY_NUMBER_IS_TOO_LARGE);
157158
}
158159

159160
stream.seek(ifd_offset);
@@ -189,7 +190,7 @@ public TIFFDirectory(RandomAccessFileOrArray stream, long ifd_offset, int direct
189190
stream.seek(0L);
190191
int endian = stream.readUnsignedShort();
191192
if (!isValidEndianTag(endian)) {
192-
throw new IOException(IOException.BadEndiannessTag0x4949Or0x4d4d);
193+
throw new IOException(IoExceptionMessageConstant.BAD_ENDIANNESS_TAG_0X4949_OR_0X4D4D);
193194
}
194195
isBigEndian = endian == 0x4d4d;
195196

@@ -698,12 +699,12 @@ public static int getNumDirectories(RandomAccessFileOrArray stream)
698699
stream.seek(0L);
699700
int endian = stream.readUnsignedShort();
700701
if (!isValidEndianTag(endian)) {
701-
throw new IOException(IOException.BadEndiannessTag0x4949Or0x4d4d);
702+
throw new IOException(IoExceptionMessageConstant.BAD_ENDIANNESS_TAG_0X4949_OR_0X4D4D);
702703
}
703704
boolean isBigEndian = endian == 0x4d4d;
704705
int magic = readUnsignedShort(stream, isBigEndian);
705706
if (magic != 42) {
706-
throw new IOException(IOException.BadMagicNumberShouldBe42);
707+
throw new IOException(IoExceptionMessageConstant.BAD_MAGIC_NUMBER_SHOULD_BE_42);
707708
}
708709

709710
stream.seek(4L);

0 commit comments

Comments
 (0)