Skip to content

Commit bfd0bd5

Browse files
String.Format() was replaced with MessageFormat
DEVSIX-354
1 parent 13eb59a commit bfd0bd5

File tree

28 files changed

+104
-72
lines changed

28 files changed

+104
-72
lines changed

io/src/main/java/com/itextpdf/io/font/FontRegisterProvider.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import org.slf4j.Logger;
66
import org.slf4j.LoggerFactory;
77

8+
import java.io.File;
9+
import java.text.MessageFormat;
810
import java.util.ArrayList;
911
import java.util.HashMap;
1012
import java.util.List;
@@ -295,7 +297,7 @@ public void register(final String path, final String alias) {
295297
trueTypeFonts.put(fullName, path);
296298
}
297299
if (LOGGER.isTraceEnabled()) {
298-
LOGGER.trace(String.format("Registered %s", path));
300+
LOGGER.trace(MessageFormat.format("Registered {0}", path));
299301
}
300302
} catch (java.io.IOException e){
301303
throw new IOException(e);
@@ -334,7 +336,7 @@ public int registerDirectory(final String dir) {
334336
*/
335337
public int registerDirectory(final String dir, final boolean scanSubdirectories) {
336338
if (LOGGER.isDebugEnabled()) {
337-
LOGGER.debug(String.format("Registering directory %s, looking for fonts", dir));
339+
LOGGER.debug(MessageFormat.format("Registering directory {0}, looking for fonts", dir));
338340
}
339341
int count = 0;
340342
try {

io/src/main/java/com/itextpdf/io/font/otf/Glyph.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
import com.itextpdf.io.util.TextUtil;
4848

4949
import java.io.Serializable;
50+
import java.text.MessageFormat;
5051
import java.util.Arrays;
5152

5253
public class Glyph implements Serializable {
@@ -247,7 +248,7 @@ public boolean equals(Object obj) {
247248
}
248249

249250
public String toString() {
250-
return String.format("[id=%d, chars=%s, uni=%d, width=%d]",
251+
return MessageFormat.format("[id={0}, chars={1}, uni={2}, width={3}]",
251252
code, chars != null ? Arrays.toString(chars) : "null", unicode, width);
252253
}
253254

io/src/main/java/com/itextpdf/io/font/otf/OtfReadCommon.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.itextpdf.io.source.RandomAccessFileOrArray;
44

5+
import java.text.MessageFormat;
56
import java.util.ArrayList;
67
import java.util.Collections;
78
import java.util.HashSet;
@@ -48,7 +49,7 @@ public static List<Integer> readCoverageFormat(RandomAccessFileOrArray rf, int c
4849
}
4950

5051
} else {
51-
throw new UnsupportedOperationException(String.format("Invalid coverage format: %d", coverageFormat));
52+
throw new UnsupportedOperationException(MessageFormat.format("Invalid coverage format: {0}", coverageFormat));
5253
}
5354

5455
return Collections.unmodifiableList(glyphIds);

io/src/main/java/com/itextpdf/io/image/JpegImageHelper.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
import com.itextpdf.io.source.ByteArrayOutputStream;
77

88
import java.io.InputStream;
9+
import java.text.MessageFormat;
910
import java.util.HashMap;
1011
import java.util.Map;
1112

@@ -287,7 +288,7 @@ private static void processParameters(InputStream jpegStream, String errorID, Im
287288
// make sure this is consistent with JFIF data
288289
if (image.getDpiX() != 0 && image.getDpiX() != dx) {
289290
Logger logger = LoggerFactory.getLogger(JpegImageHelper.class);
290-
logger.debug(String.format("Inconsistent metadata (dpiX: %d vs %d)", image.getDpiX(), dx));
291+
logger.debug(MessageFormat.format("Inconsistent metadata (dpiX: {0} vs {1})", image.getDpiX(), dx));
291292
} else {
292293
image.setDpi(dx, image.getDpiY());
293294
}
@@ -297,7 +298,7 @@ private static void processParameters(InputStream jpegStream, String errorID, Im
297298
// make sure this is consistent with JFIF data
298299
if (image.getDpiY() != 0 && image.getDpiY() != dy) {
299300
Logger logger = LoggerFactory.getLogger(JpegImageHelper.class);
300-
logger.debug(String.format("Inconsistent metadata (dpiY: %d vs %d)", image.getDpiY(), dy));
301+
logger.debug(MessageFormat.format("Inconsistent metadata (dpiY: {0} vs {1})", image.getDpiY(), dy));
301302
} else {
302303
image.setDpi(image.getDpiX(), dx);
303304
}

io/src/main/java/com/itextpdf/io/image/PngImageHelper.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.io.ByteArrayInputStream;
1212
import java.io.DataInputStream;
1313
import java.io.InputStream;
14+
import java.text.MessageFormat;
1415
import java.util.HashMap;
1516
import java.util.Map;
1617

@@ -179,7 +180,7 @@ private static void processPng(InputStream pngStream, PngParameters png) throws
179180
png.palShades = true;
180181
png.genBWMask = (!png.palShades && (pal0 > 1 || png.transRedGray >= 0));
181182
if (!png.palShades && !png.genBWMask && pal0 == 1) {
182-
png.additional.put("Mask", String.format("[%d %d]", palIdx, palIdx));
183+
png.additional.put("Mask", MessageFormat.format("[{0} {1}]", palIdx, palIdx));
183184
}
184185
boolean needDecode = (png.interlaceMethod == 1) || (png.bitDepth == 16) || ((png.colorType & 4) != 0) || png.palShades || png.genBWMask;
185186
switch (png.colorType) {
@@ -348,7 +349,7 @@ private static void readPng(InputStream pngStream, PngParameters png) throws jav
348349
if (png.bitDepth == 16)
349350
png.transRedGray = gray;
350351
else
351-
png.additional.put("Mask", String.format("[%d %d]", gray, gray));
352+
png.additional.put("Mask", MessageFormat.format("[{0} {1}]", gray, gray));
352353
}
353354
break;
354355
case 2:
@@ -362,7 +363,7 @@ private static void readPng(InputStream pngStream, PngParameters png) throws jav
362363
png.transGreen = green;
363364
png.transBlue = blue;
364365
} else
365-
png.additional.put("Mask", String.format("[%d %d %d %d %d %d]", red, red, green, green, blue, blue));
366+
png.additional.put("Mask", MessageFormat.format("[{0} {1} {2} {3} {4} {5}]", red, red, green, green, blue, blue));
366367
}
367368
break;
368369
case 3:

io/src/main/java/com/itextpdf/io/source/ByteBuffer.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.itextpdf.io.source;
22

33
import java.io.Serializable;
4+
import java.text.MessageFormat;
45

56
public class ByteBuffer implements Serializable{
67

@@ -77,7 +78,7 @@ public ByteBuffer appendHex(byte b) {
7778

7879
public byte get(int index) {
7980
if (index >= count) {
80-
throw new IndexOutOfBoundsException(String.format("Index: %d, Size: %d", index, count));
81+
throw new IndexOutOfBoundsException(MessageFormat.format("Index: {0}, Size: {1}", index, count));
8182
}
8283
return buffer[index];
8384
}

io/src/main/java/com/itextpdf/io/util/IntHashtable.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.itextpdf.io.util;
22

33
import java.io.Serializable;
4+
import java.text.MessageFormat;
45
import java.util.Arrays;
56
import java.util.Iterator;
67
import java.util.NoSuchElementException;
@@ -79,10 +80,10 @@ public IntHashtable(int initialCapacity) {
7980
public IntHashtable(int initialCapacity, float loadFactor) {
8081
super();
8182
if (initialCapacity < 0) {
82-
throw new IllegalArgumentException(String.format("Illegal Capacity: %d", initialCapacity));
83+
throw new IllegalArgumentException(MessageFormat.format("Illegal Capacity: {0}", initialCapacity));
8384
}
8485
if (loadFactor <= 0) {
85-
throw new IllegalArgumentException(String.format("Illegal Load: %f", loadFactor));
86+
throw new IllegalArgumentException(MessageFormat.format("Illegal Load: {0}", loadFactor));
8687
}
8788
if (initialCapacity == 0) {
8889
initialCapacity = 1;

kernel/src/main/java/com/itextpdf/kernel/font/PdfType0Font.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public class PdfType0Font extends PdfSimpleFont<FontProgram> {
147147
}
148148
}
149149
if (fontProgram == null) {
150-
throw new PdfException(String.format("Cannot recognise document font %s with %s encoding", cidFontName, cmap));
150+
throw new PdfException(MessageFormat.format("Cannot recognise document font {0} with {1} encoding", cidFontName, cmap));
151151
}
152152
cidFontType = CidFontType0;
153153
}
@@ -429,7 +429,7 @@ private void flushFontData() {
429429
if (style.length() > 0) {
430430
name += "-" + style;
431431
}
432-
getPdfObject().put(PdfName.BaseFont, new PdfName(String.format("%s-%s", name, cmapEncoding.getCmapName())));
432+
getPdfObject().put(PdfName.BaseFont, new PdfName(MessageFormat.format("{0}-{1}", name, cmapEncoding.getCmapName())));
433433
getPdfObject().put(PdfName.Encoding, new PdfName(cmapEncoding.getCmapName()));
434434
PdfDictionary fontDescriptor = getFontDescriptor(name);
435435
int[][] metrics = longTag.values().toArray(new int[0][]);
@@ -459,7 +459,7 @@ private void flushFontData() {
459459
fontStream.put(PdfName.Subtype, new PdfName("CIDFontType0C"));
460460
// The PDF Reference manual advises to add -cmap in case CIDFontType0
461461
getPdfObject().put(PdfName.BaseFont,
462-
new PdfName(String.format("%s-%s", fontName, cmapEncoding.getCmapName())));
462+
new PdfName(MessageFormat.format("{0}-{1}", fontName, cmapEncoding.getCmapName())));
463463
fontDescriptor.put(PdfName.FontFile3, fontStream);
464464
} else {
465465
byte[] ttfBytes;

kernel/src/main/java/com/itextpdf/kernel/parser/TextMarginFinder.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import com.itextpdf.kernel.geom.Rectangle;
44

5+
import java.text.MessageFormat;
56
import java.util.Collections;
67
import java.util.LinkedHashSet;
78
import java.util.Set;
@@ -24,7 +25,7 @@ public void eventOccurred(EventData data, EventType type) {
2425
}
2526
textRectangle = Rectangle.getCommonRectangle(textRectangle, info.getAscentLine().getBoundingRectange());
2627
} else {
27-
throw new IllegalStateException(String.format("Event type not supported: %s", type));
28+
throw new IllegalStateException(MessageFormat.format("Event type not supported: {0}", type));
2829
}
2930
}
3031

kernel/src/main/java/com/itextpdf/kernel/pdf/PdfIndirectReference.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.itextpdf.kernel.pdf;
22

3+
import java.text.MessageFormat;
4+
35
public class PdfIndirectReference extends PdfObject implements Comparable<PdfIndirectReference> {
46

57
private static final long serialVersionUID = -8293603068792908601L;
@@ -203,7 +205,7 @@ public String toString() {
203205
if (checkState(ReadOnly)) {
204206
states.append("ReadOnly; ");
205207
}
206-
return java.lang.String.format("%d %d R%s", getObjNumber(), getGenNumber(), states.substring(0, states.length() - 1));
208+
return MessageFormat.format("{0} {1} R{2}", getObjNumber(), getGenNumber(), states.substring(0, states.length() - 1));
207209
}
208210

209211
protected void setObjStreamNumber(int objectStreamNumber) {

0 commit comments

Comments
 (0)