Skip to content

Commit 5bf4338

Browse files
committed
Restrict the scope of methods for internal usage
1 parent 1fc859b commit 5bf4338

File tree

4 files changed

+41
-29
lines changed

4 files changed

+41
-29
lines changed

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,14 @@ public OutputStream(java.io.OutputStream outputStream) {
2424
this.outputStream = outputStream;
2525
}
2626

27+
/**
28+
* Do not use this constructor. This is only for internal usage.
29+
*/
30+
protected OutputStream() {
31+
super();
32+
this.outputStream = new ByteArrayOutputStream();
33+
}
34+
2735
@Override
2836
public void write(int b) throws java.io.IOException {
2937
outputStream.write(b);

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -524,22 +524,6 @@ public PageSize getDefaultPageSize() {
524524
return defaultPageSize;
525525
}
526526

527-
public byte[] getSerializedBytes() {
528-
try {
529-
ByteArrayOutputStream bos = new ByteArrayOutputStream();
530-
ObjectOutputStream oos = null;
531-
oos = new ObjectOutputStream(bos);
532-
oos.writeObject(this);
533-
oos.flush();
534-
oos.close();
535-
bos.close();
536-
return bos.toByteArray();
537-
} catch (IOException e) {
538-
e.printStackTrace();
539-
}
540-
return null;
541-
}
542-
543527
/**
544528
* Sets default page size.
545529
*
@@ -1500,4 +1484,18 @@ private void ensureTreeRootAddedToNames(PdfObject treeRoot, PdfName treeType) {
15001484
}
15011485
names.put(treeType, treeRoot);
15021486
}
1487+
1488+
private byte[] getSerializedBytes() {
1489+
try {
1490+
ByteArrayOutputStream bos = new ByteArrayOutputStream();
1491+
ObjectOutputStream oos = new ObjectOutputStream(bos);
1492+
oos.writeObject(this);
1493+
oos.flush();
1494+
oos.close();
1495+
bos.close();
1496+
return bos.toByteArray();
1497+
} catch (IOException e) {
1498+
throw new PdfException(e);
1499+
}
1500+
}
15031501
}

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,12 @@
11
package com.itextpdf.kernel.pdf;
22

3-
import com.itextpdf.io.source.ByteUtils;
4-
import com.itextpdf.kernel.PdfException;
53
import com.itextpdf.io.source.ByteArrayOutputStream;
4+
import com.itextpdf.io.source.ByteUtils;
65
import com.itextpdf.io.source.OutputStream;
6+
import com.itextpdf.kernel.PdfException;
77
import com.itextpdf.kernel.crypto.OutputStreamEncryption;
88
import com.itextpdf.kernel.pdf.filters.FlateDecodeFilter;
99

10-
import java.io.FileNotFoundException;
11-
import java.io.FileOutputStream;
1210
import java.io.IOException;
1311
import java.io.Serializable;
1412
import java.security.cert.Certificate;
@@ -130,7 +128,10 @@ public class PdfOutputStream extends OutputStream<PdfOutputStream> implements Se
130128
*/
131129
protected PdfEncryption crypto;
132130

133-
protected PdfOutputStream() {
131+
/**
132+
* Do not use this constructor. This is only for internal usage.
133+
*/
134+
private PdfOutputStream() {
134135
super();
135136
}
136137

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@
44
import com.itextpdf.io.source.ByteUtils;
55
import com.itextpdf.kernel.PdfException;
66

7-
import java.io.*;
7+
import java.io.BufferedOutputStream;
88
import java.io.ByteArrayOutputStream;
9-
import java.io.OutputStream;
9+
import java.io.FileNotFoundException;
10+
import java.io.FileOutputStream;
11+
import java.io.IOException;
12+
import java.io.Serializable;
1013
import java.security.MessageDigest;
1114
import java.util.Arrays;
1215
import java.util.HashMap;
@@ -375,9 +378,10 @@ protected int getCopyObjectKey(PdfObject object) {
375378
return result;
376379
}
377380

378-
//method invoking while deserialization
379-
private void readObject(java.io.ObjectInputStream in)
380-
throws java.io.IOException, ClassNotFoundException {
381+
/**
382+
* This method is invoked while deserialization
383+
*/
384+
private void readObject(java.io.ObjectInputStream in) throws java.io.IOException, ClassNotFoundException {
381385
in.defaultReadObject();
382386
this.outputStream = new BufferedOutputStream(new ByteArrayOutputStream());
383387
content = new PdfOutputStream(new ByteArrayOutputStream());
@@ -406,9 +410,10 @@ private PdfObject smartCopyObject(PdfObject object) {
406410
return null;
407411
}
408412

409-
//method invoking while serialization
410-
private void writeObject(java.io.ObjectOutputStream out)
411-
throws java.io.IOException {
413+
/**
414+
* This method is invoked while serialization
415+
*/
416+
private void writeObject(java.io.ObjectOutputStream out) throws java.io.IOException {
412417
content.flush();
413418
buffer = getByteArrayOutputStream().toByteArray();
414419
out.defaultWriteObject();

0 commit comments

Comments
 (0)