Skip to content

Commit 319cc9c

Browse files
committed
Mark specific PdfOutputStream#write() methods as private
1 parent d10bb4d commit 319cc9c

File tree

2 files changed

+39
-50
lines changed

2 files changed

+39
-50
lines changed

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

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ public PdfOutputStream write(PdfObject pdfObject) {
101101
write((PdfArray) pdfObject);
102102
break;
103103
case PdfObject.DICTIONARY:
104-
writePdfDictionary((PdfDictionary) pdfObject);
104+
write((PdfDictionary) pdfObject);
105105
break;
106106
case PdfObject.INDIRECT_REFERENCE:
107107
write((PdfIndirectReference) pdfObject);
@@ -129,7 +129,7 @@ public PdfOutputStream write(PdfObject pdfObject) {
129129
return this;
130130
}
131131

132-
protected void write(PdfArray pdfArray) {
132+
private void write(PdfArray pdfArray) {
133133
writeByte('[');
134134
for (int i = 0; i < pdfArray.size(); i++) {
135135
PdfObject value = pdfArray.get(i, false);
@@ -145,7 +145,7 @@ protected void write(PdfArray pdfArray) {
145145
writeByte(']');
146146
}
147147

148-
protected void writePdfDictionary(PdfDictionary pdfDictionary) {
148+
private void write(PdfDictionary pdfDictionary) {
149149
writeBytes(openDict);
150150
for (Map.Entry<PdfName, PdfObject> entry : pdfDictionary.entrySet()) {
151151
boolean isAlreadyWriteSpace = false;
@@ -179,7 +179,7 @@ protected void writePdfDictionary(PdfDictionary pdfDictionary) {
179179
writeBytes(closeDict);
180180
}
181181

182-
protected void write(PdfIndirectReference indirectReference) {
182+
private void write(PdfIndirectReference indirectReference) {
183183
if (document != null && !indirectReference.getDocument().equals(document)) {
184184
throw new PdfException(PdfException.PdfInderectObjectBelongToOtherPdfDocument);
185185
}
@@ -196,16 +196,16 @@ protected void write(PdfIndirectReference indirectReference) {
196196
}
197197
}
198198

199-
protected void write(PdfPrimitiveObject pdfPrimitive) {
199+
private void write(PdfPrimitiveObject pdfPrimitive) {
200200
writeBytes(pdfPrimitive.getInternalContent());
201201
}
202202

203-
protected void write(PdfLiteral literal) {
203+
private void write(PdfLiteral literal) {
204204
literal.setPosition(getCurrentPos());
205205
writeBytes(literal.getInternalContent());
206206
}
207207

208-
protected void write(PdfString pdfString) {
208+
private void write(PdfString pdfString) {
209209
pdfString.encrypt(crypto);
210210
if (pdfString.isHexWriting()) {
211211
writeByte('<');
@@ -219,12 +219,12 @@ protected void write(PdfString pdfString) {
219219
}
220220

221221

222-
protected void write(PdfName name) {
222+
private void write(PdfName name) {
223223
writeByte('/');
224224
writeBytes(name.getInternalContent());
225225
}
226226

227-
protected void write(PdfNumber pdfNumber) {
227+
private void write(PdfNumber pdfNumber) {
228228
if (pdfNumber.hasContent()) {
229229
writeBytes(pdfNumber.getInternalContent());
230230
} else if (pdfNumber.isDoubleNumber()) {
@@ -240,7 +240,7 @@ private boolean isNotMetadataPdfStream(PdfStream pdfStream) {
240240

241241
}
242242

243-
protected void write(PdfStream pdfStream) {
243+
private void write(PdfStream pdfStream) {
244244
try {
245245
boolean userDefinedCompression = pdfStream.getCompressionLevel() != CompressionConstants.UNDEFINED_COMPRESSION;
246246
if (!userDefinedCompression) {
@@ -263,7 +263,7 @@ protected void write(PdfStream pdfStream) {
263263
updateCompressionFilter(pdfStream);
264264
fout = def = new DeflaterOutputStream(fout, pdfStream.getCompressionLevel(), 0x8000);
265265
}
266-
writePdfDictionary(pdfStream);
266+
this.write((PdfDictionary) pdfStream);
267267
writeBytes(PdfOutputStream.stream);
268268
long beginStreamContent = getCurrentPos();
269269
byte buf[] = new byte[4192];
@@ -336,7 +336,7 @@ protected void write(PdfStream pdfStream) {
336336
}
337337
pdfStream.put(PdfName.Length, new PdfNumber(byteArrayStream.size()));
338338
pdfStream.updateLength((int) byteArrayStream.size());
339-
writePdfDictionary(pdfStream);
339+
this.write((PdfDictionary) pdfStream);
340340
writeBytes(PdfOutputStream.stream);
341341
byteArrayStream.writeTo(this);
342342
writeBytes(PdfOutputStream.endstream);
@@ -413,9 +413,9 @@ protected void updateCompressionFilter(PdfStream pdfStream) {
413413

414414
protected byte[] decodeFlateBytes(PdfStream stream, byte[] bytes) {
415415
PdfObject filterObject = stream.get(PdfName.Filter);
416-
if (filterObject == null)
416+
if (filterObject == null) {
417417
return bytes;
418-
418+
}
419419
// check if flateDecode filter is on top
420420
PdfName filterName;
421421
PdfArray filtersArray = null;
@@ -475,15 +475,17 @@ protected byte[] decodeFlateBytes(PdfStream stream, byte[] bytes) {
475475
}
476476
}
477477

478-
if (filterObject == null)
478+
if (filterObject == null) {
479479
stream.remove(PdfName.Filter);
480-
else
480+
} else {
481481
stream.put(PdfName.Filter, filterObject);
482+
}
482483

483-
if (decodeParamsObject == null)
484+
if (decodeParamsObject == null) {
484485
stream.remove(PdfName.DecodeParms);
485-
else
486+
} else {
486487
stream.put(PdfName.DecodeParms, decodeParamsObject);
488+
}
487489

488490
return bytes;
489491
}
@@ -512,5 +514,4 @@ private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOExcept
512514
out.defaultWriteObject();
513515
outputStream = tempOutputStream;
514516
}
515-
516517
}

kernel/src/main/java/com/itextpdf/kernel/pdf/canvas/PdfCanvas.java

Lines changed: 19 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,7 @@ public PdfCanvas setFontAndSize(PdfFont font, float size) {
436436
PdfName fontName = resources.addFont(document, font);
437437
currentGs.setFont(font);
438438
contentStream.getOutputStream()
439-
.write((PdfObject) fontName)
439+
.write(fontName)
440440
.writeSpace()
441441
.writeFloat(size).writeSpace()
442442
.writeBytes(Tf);
@@ -930,8 +930,8 @@ public PdfCanvas arc(final double x1, final double y1, final double x2, final do
930930
return this;
931931
double pt[] = ar.get(0);
932932
moveTo(pt[0], pt[1]);
933-
for (int iter = 0; iter < ar.size(); ++iter) {
934-
pt = ar.get(iter);
933+
for (int i = 0; i < ar.size(); ++i) {
934+
pt = ar.get(i);
935935
curveTo(pt[2], pt[3], pt[4], pt[5], pt[6], pt[7]);
936936
}
937937

@@ -1431,7 +1431,7 @@ public PdfCanvas setRenderingIntent(PdfName renderingIntent) {
14311431
return this;
14321432
currentGs.setRenderingIntent(renderingIntent);
14331433
contentStream.getOutputStream()
1434-
.write((PdfObject) renderingIntent).writeSpace()
1434+
.write(renderingIntent).writeSpace()
14351435
.writeBytes(ri);
14361436
return this;
14371437
}
@@ -1533,15 +1533,15 @@ else if (colorSpace instanceof PdfDeviceCs.Rgb)
15331533
else if (colorSpace instanceof PdfDeviceCs.Cmyk)
15341534
contentStream.getOutputStream().writeFloats(colorValue).writeSpace().writeBytes(fill ? k : K);
15351535
else if (colorSpace instanceof PdfSpecialCs.UncoloredTilingPattern)
1536-
contentStream.getOutputStream().write((PdfObject) resources.addColorSpace(colorSpace)).writeSpace().writeBytes(fill ? cs : CS).
1537-
writeNewLine().writeFloats(colorValue).writeSpace().write((PdfObject) resources.addPattern(pattern)).writeSpace().writeBytes(fill ? scn : SCN);
1536+
contentStream.getOutputStream().write(resources.addColorSpace(colorSpace)).writeSpace().writeBytes(fill ? cs : CS).
1537+
writeNewLine().writeFloats(colorValue).writeSpace().write(resources.addPattern(pattern)).writeSpace().writeBytes(fill ? scn : SCN);
15381538
else if (colorSpace instanceof PdfSpecialCs.Pattern)
1539-
contentStream.getOutputStream().write((PdfObject) PdfName.Pattern).writeSpace().writeBytes(fill ? cs : CS).
1540-
writeNewLine().write((PdfObject) resources.addPattern(pattern)).writeSpace().writeBytes(fill ? scn : SCN);
1539+
contentStream.getOutputStream().write(PdfName.Pattern).writeSpace().writeBytes(fill ? cs : CS).
1540+
writeNewLine().write(resources.addPattern(pattern)).writeSpace().writeBytes(fill ? scn : SCN);
15411541
else if (colorSpace.getPdfObject().isIndirect()) {
15421542
if (!setColorValueOnly) {
15431543
PdfName name = resources.addColorSpace(colorSpace);
1544-
contentStream.getOutputStream().write((PdfObject) name).writeSpace().writeBytes(fill ? cs : CS);
1544+
contentStream.getOutputStream().write(name).writeSpace().writeBytes(fill ? cs : CS);
15451545
}
15461546
contentStream.getOutputStream().writeFloats(colorValue).writeSpace().writeBytes(fill ? scn : SCN);
15471547
}
@@ -1732,7 +1732,7 @@ public PdfCanvas beginLayer(IPdfOCG layer) {
17321732
* @return current canvas.
17331733
*/
17341734
public PdfCanvas endLayer() {
1735-
int num = 1;
1735+
int num;
17361736
if (layerDepth != null && !layerDepth.isEmpty()) {
17371737
num = layerDepth.get(layerDepth.size() - 1);
17381738
layerDepth.remove(layerDepth.size() - 1);
@@ -1844,7 +1844,6 @@ public PdfXObject addImage(Image image, float x, float y, boolean asInline) {
18441844
* @param width
18451845
* @param asInline true if to add image as in-line.
18461846
* @return created XObject or null in case of in-line image (asInline = true).
1847-
* @on error.
18481847
*/
18491848
public PdfXObject addImage(Image image, float x, float y, float width, boolean asInline) {
18501849
if (image.getOriginalType() == ImageType.WMF) {
@@ -1892,7 +1891,6 @@ public PdfXObject addImage(Image image, float x, float y, float height, boolean
18921891
* @param e an element of the transformation matrix
18931892
* @param f an element of the transformation matrix
18941893
* @return current canvas.
1895-
* @on error.
18961894
*/
18971895
public PdfCanvas addXObject(PdfXObject xObject, float a, float b, float c, float d, float e, float f) {
18981896
if (xObject instanceof PdfFormXObject) {
@@ -1911,7 +1909,6 @@ public PdfCanvas addXObject(PdfXObject xObject, float a, float b, float c, float
19111909
* @param x
19121910
* @param y
19131911
* @return current canvas.
1914-
* @on error.
19151912
*/
19161913
public PdfCanvas addXObject(PdfXObject xObject, float x, float y) {
19171914
if (xObject instanceof PdfFormXObject) {
@@ -1929,7 +1926,6 @@ public PdfCanvas addXObject(PdfXObject xObject, float x, float y) {
19291926
* @param xObject
19301927
* @param rect
19311928
* @return current canvas.
1932-
* @on error.
19331929
*/
19341930
public PdfCanvas addXObject(PdfXObject xObject, Rectangle rect) {
19351931
if (xObject instanceof PdfFormXObject) {
@@ -1949,7 +1945,6 @@ public PdfCanvas addXObject(PdfXObject xObject, Rectangle rect) {
19491945
* @param y
19501946
* @param width
19511947
* @return current canvas.
1952-
* @on error.
19531948
*/
19541949
public PdfCanvas addXObject(PdfXObject xObject, float x, float y, float width) {
19551950
if (xObject instanceof PdfFormXObject) {
@@ -1970,7 +1965,6 @@ public PdfCanvas addXObject(PdfXObject xObject, float x, float y, float width) {
19701965
* @param height
19711966
* @param dummy
19721967
* @return current canvas.
1973-
* @on error.
19741968
*/
19751969
public PdfCanvas addXObject(PdfXObject xObject, float x, float y, float height, boolean dummy) {
19761970
if (xObject instanceof PdfFormXObject) {
@@ -1992,7 +1986,7 @@ public PdfCanvas setExtGState(PdfExtGState extGState) {
19921986
if (!extGState.isFlushed())
19931987
currentGs.updateFromExtGState(extGState);
19941988
PdfName name = resources.addExtGState(extGState);
1995-
contentStream.getOutputStream().write((PdfObject) name).writeSpace().writeBytes(gs);
1989+
contentStream.getOutputStream().write(name).writeSpace().writeBytes(gs);
19961990
return this;
19971991
}
19981992

@@ -2027,13 +2021,13 @@ public PdfCanvas beginMarkedContent(PdfName tag) {
20272021
*/
20282022
public PdfCanvas beginMarkedContent(PdfName tag, PdfDictionary properties) {
20292023
mcDepth++;
2030-
PdfOutputStream out = contentStream.getOutputStream().write((PdfObject) tag).writeSpace();
2024+
PdfOutputStream out = contentStream.getOutputStream().write(tag).writeSpace();
20312025
if (properties == null) {
20322026
out.writeBytes(BMC);
20332027
} else if (properties.getIndirectReference() == null) {
20342028
out.write(properties).writeSpace().writeBytes(BDC);
20352029
} else {
2036-
out.write((PdfObject) resources.addProperties(properties)).writeSpace().writeBytes(BDC);
2030+
out.write(resources.addProperties(properties)).writeSpace().writeBytes(BDC);
20372031
}
20382032
return this;
20392033
}
@@ -2152,7 +2146,7 @@ protected void addInlineImage(PdfImageXObject imageXObject, float a, float b, fl
21522146
for (Map.Entry<PdfName, PdfObject> entry : imageXObject.getPdfObject().entrySet()) {
21532147
PdfName key = entry.getKey();
21542148
if (!PdfName.Type.equals(key) && !PdfName.Subtype.equals(key) && !PdfName.Length.equals(key)) {
2155-
os.write((PdfObject) entry.getKey()).writeSpace();
2149+
os.write(entry.getKey()).writeSpace();
21562150
os.write(entry.getValue()).writeNewLine();
21572151
}
21582152
}
@@ -2177,7 +2171,7 @@ private PdfCanvas addForm(PdfFormXObject form, float a, float b, float c, float
21772171
saveState();
21782172
concatMatrix(a, b, c, d, e, f);
21792173
PdfName name = resources.addForm(form);
2180-
contentStream.getOutputStream().write((PdfObject) name).writeSpace().writeBytes(Do);
2174+
contentStream.getOutputStream().write(name).writeSpace().writeBytes(Do);
21812175
restoreState();
21822176
return this;
21832177
}
@@ -2235,7 +2229,6 @@ private PdfCanvas addForm(PdfFormXObject form, float x, float y, float width) {
22352229
* @param height
22362230
* @param dummy
22372231
* @return
2238-
* @on error.
22392232
*/
22402233
private PdfCanvas addForm(PdfFormXObject form, float x, float y, float height, boolean dummy) {
22412234
PdfArray bbox = form.getPdfObject().getAsArray(PdfName.BBox);
@@ -2257,13 +2250,12 @@ private PdfCanvas addForm(PdfFormXObject form, float x, float y, float height, b
22572250
* @param e an element of the transformation matrix
22582251
* @param f an element of the transformation matrix
22592252
* @return canvas a reference to this object.
2260-
* @on error
22612253
*/
22622254
private PdfCanvas addImage(PdfImageXObject image, float a, float b, float c, float d, float e, float f) {
22632255
saveState();
22642256
concatMatrix(a, b, c, d, e, f);
22652257
PdfName name = resources.addImage(image);
2266-
contentStream.getOutputStream().write((PdfObject) name).writeSpace().writeBytes(Do);
2258+
contentStream.getOutputStream().write(name).writeSpace().writeBytes(Do);
22672259
restoreState();
22682260
return this;
22692261
}
@@ -2272,7 +2264,7 @@ private PdfCanvas addImage(PdfXObject xObject, float a, float b, float c, float
22722264
saveState();
22732265
concatMatrix(a, b, c, d, e, f);
22742266
PdfName name = resources.addImage(xObject.getPdfObject());
2275-
contentStream.getOutputStream().write((PdfObject) name).writeSpace().writeBytes(Do);
2267+
contentStream.getOutputStream().write(name).writeSpace().writeBytes(Do);
22762268
restoreState();
22772269
return this;
22782270
}
@@ -2284,7 +2276,6 @@ private PdfCanvas addImage(PdfXObject xObject, float a, float b, float c, float
22842276
* @param x
22852277
* @param y
22862278
* @return
2287-
* @throws PdfException
22882279
*/
22892280
private PdfCanvas addImage(PdfImageXObject image, float x, float y) {
22902281
return addImage(image, image.getWidth(), 0, 0, image.getHeight(), x, y);
@@ -2296,7 +2287,6 @@ private PdfCanvas addImage(PdfImageXObject image, float x, float y) {
22962287
* @param image
22972288
* @param rect
22982289
* @return
2299-
* @throws PdfException
23002290
*/
23012291
private PdfCanvas addImage(PdfImageXObject image, Rectangle rect) {
23022292
return addImage(image, rect.getWidth(), 0, 0, rect.getHeight(), rect.getX(), rect.getY());
@@ -2310,7 +2300,6 @@ private PdfCanvas addImage(PdfImageXObject image, Rectangle rect) {
23102300
* @param y
23112301
* @param width
23122302
* @return
2313-
* @throws PdfException
23142303
*/
23152304
private PdfCanvas addImage(PdfImageXObject image, float x, float y, float width) {
23162305
return addImage(image, width, 0, 0, width / image.getWidth() * image.getHeight(), x, y);
@@ -2325,7 +2314,6 @@ private PdfCanvas addImage(PdfImageXObject image, float x, float y, float width)
23252314
* @param height
23262315
* @param dummy
23272316
* @return current canvas.
2328-
* @on error.
23292317
*/
23302318
private PdfCanvas addImage(PdfImageXObject image, float x, float y, float height, boolean dummy) {
23312319
return addImage(image, height / image.getHeight() * image.getWidth(), 0, 0, height, x, y);
@@ -2366,8 +2354,8 @@ private void showTextInt(String text) {
23662354

23672355
private void addToPropertiesAndBeginLayer(IPdfOCG layer) {
23682356
PdfName name = resources.addProperties(layer.getPdfObject());
2369-
contentStream.getOutputStream().write((PdfObject) PdfName.OC).writeSpace()
2370-
.write((PdfObject) name).writeSpace().writeBytes(BDC).writeNewLine();
2357+
contentStream.getOutputStream().write(PdfName.OC).writeSpace()
2358+
.write(name).writeSpace().writeBytes(BDC).writeNewLine();
23712359
}
23722360

23732361
private Color createColor(PdfColorSpace colorSpace, float[] colorValue, PdfPattern pattern) {

0 commit comments

Comments
 (0)