Skip to content

Commit b97211c

Browse files
committed
Rename kernel.pdf.ByteBuffer to ByteBufferOutputStream.
1 parent 1b44f24 commit b97211c

File tree

3 files changed

+46
-48
lines changed

3 files changed

+46
-48
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ This file is part of the iText (R) project.
4747
import java.io.Serializable;
4848
import java.text.MessageFormat;
4949

50-
public class ByteBuffer implements Serializable{
50+
public class ByteBuffer implements Serializable {
5151

5252
private static final byte[] bytes = new byte[]{48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 97, 98, 99, 100, 101, 102};
5353

kernel/src/main/java/com/itextpdf/kernel/pdf/ByteBuffer.java renamed to kernel/src/main/java/com/itextpdf/kernel/pdf/ByteBufferOutputStream.java

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
* @author Paulo Soares
6161
*/
6262

63-
public class ByteBuffer extends OutputStream {
63+
public class ByteBufferOutputStream extends OutputStream {
6464
/** The count of bytes in the buffer. */
6565
protected int count;
6666

@@ -80,16 +80,16 @@ public class ByteBuffer extends OutputStream {
8080
public static boolean HIGH_PRECISION = false;
8181
private static final DecimalFormatSymbols dfs = new DecimalFormatSymbols(Locale.US);
8282

83-
/** Creates new ByteBuffer with capacity 128 */
84-
public ByteBuffer() {
83+
/** Creates new ByteBufferOutputStream with capacity 128 */
84+
public ByteBufferOutputStream() {
8585
this(128);
8686
}
8787

8888
/**
8989
* Creates a byte buffer with a certain capacity.
9090
* @param size the initial capacity
9191
*/
92-
public ByteBuffer(int size) {
92+
public ByteBufferOutputStream(int size) {
9393
if (size < 1)
9494
size = 128;
9595
buf = new byte[size];
@@ -181,9 +181,9 @@ private static byte[] convertToBytes(int i) {
181181
/**
182182
* Appends an <CODE>int</CODE>. The size of the array will grow by one.
183183
* @param b the int to be appended
184-
* @return a reference to this <CODE>ByteBuffer</CODE> object
184+
* @return a reference to this <CODE>ByteBufferOutputStream</CODE> object
185185
*/
186-
public ByteBuffer append_i(int b) {
186+
public ByteBufferOutputStream append_i(int b) {
187187
int newcount = count + 1;
188188
if (newcount > buf.length) {
189189
byte[] newbuf = new byte[Math.max(buf.length << 1, newcount)];
@@ -201,9 +201,9 @@ public ByteBuffer append_i(int b) {
201201
* @param b the array to be appended
202202
* @param off the offset to the start of the array
203203
* @param len the length of bytes to append
204-
* @return a reference to this <CODE>ByteBuffer</CODE> object
204+
* @return a reference to this <CODE>ByteBufferOutputStream</CODE> object
205205
*/
206-
public ByteBuffer append(byte[] b, int off, int len) {
206+
public ByteBufferOutputStream append(byte[] b, int off, int len) {
207207
if ((off < 0) || (off > b.length) || (len < 0) ||
208208
((off + len) > b.length) || ((off + len) < 0) || len == 0)
209209
return this;
@@ -221,19 +221,19 @@ public ByteBuffer append(byte[] b, int off, int len) {
221221
/**
222222
* Appends an array of bytes.
223223
* @param b the array to be appended
224-
* @return a reference to this <CODE>ByteBuffer</CODE> object
224+
* @return a reference to this <CODE>ByteBufferOutputStream</CODE> object
225225
*/
226-
public ByteBuffer append(byte[] b) {
226+
public ByteBufferOutputStream append(byte[] b) {
227227
return append(b, 0, b.length);
228228
}
229229

230230
/**
231231
* Appends a <CODE>String</CODE> to the buffer. The <CODE>String</CODE> is
232232
* converted according to the encoding ISO-8859-1.
233233
* @param str the <CODE>String</CODE> to be appended
234-
* @return a reference to this <CODE>ByteBuffer</CODE> object
234+
* @return a reference to this <CODE>ByteBufferOutputStream</CODE> object
235235
*/
236-
public ByteBuffer append(String str) {
236+
public ByteBufferOutputStream append(String str) {
237237
if (str != null)
238238
return append(str.getBytes());
239239
return this;
@@ -243,44 +243,44 @@ public ByteBuffer append(String str) {
243243
* Appends a <CODE>char</CODE> to the buffer. The <CODE>char</CODE> is
244244
* converted according to the encoding ISO-8859-1.
245245
* @param c the <CODE>char</CODE> to be appended
246-
* @return a reference to this <CODE>ByteBuffer</CODE> object
246+
* @return a reference to this <CODE>ByteBufferOutputStream</CODE> object
247247
*/
248-
public ByteBuffer append(char c) {
248+
public ByteBufferOutputStream append(char c) {
249249
return append_i(c);
250250
}
251251

252252
/**
253-
* Appends another <CODE>ByteBuffer</CODE> to this buffer.
254-
* @param buf the <CODE>ByteBuffer</CODE> to be appended
255-
* @return a reference to this <CODE>ByteBuffer</CODE> object
253+
* Appends another <CODE>ByteBufferOutputStream</CODE> to this buffer.
254+
* @param buf the <CODE>ByteBufferOutputStream</CODE> to be appended
255+
* @return a reference to this <CODE>ByteBufferOutputStream</CODE> object
256256
*/
257-
public ByteBuffer append(ByteBuffer buf) {
257+
public ByteBufferOutputStream append(ByteBufferOutputStream buf) {
258258
return append(buf.buf, 0, buf.count);
259259
}
260260

261261
/**
262262
* Appends the string representation of an <CODE>int</CODE>.
263263
* @param i the <CODE>int</CODE> to be appended
264-
* @return a reference to this <CODE>ByteBuffer</CODE> object
264+
* @return a reference to this <CODE>ByteBufferOutputStream</CODE> object
265265
*/
266-
public ByteBuffer append(int i) {
266+
public ByteBufferOutputStream append(int i) {
267267
return append((double)i);
268268
}
269269

270270
/**
271271
* Appends the string representation of a <CODE>long</CODE>.
272272
* @param i the <CODE>long</CODE> to be appended
273-
* @return a reference to this <CODE>ByteBuffer</CODE> object
273+
* @return a reference to this <CODE>ByteBufferOutputStream</CODE> object
274274
*/
275-
public ByteBuffer append(long i) {
275+
public ByteBufferOutputStream append(long i) {
276276
return append(Long.toString(i));
277277
}
278278

279-
public ByteBuffer append(byte b) {
279+
public ByteBufferOutputStream append(byte b) {
280280
return append_i(b);
281281
}
282282

283-
public ByteBuffer appendHex(byte b) {
283+
public ByteBufferOutputStream appendHex(byte b) {
284284
append(bytes[(b >> 4) & 0x0f]);
285285
return append(bytes[b & 0x0f]);
286286
}
@@ -289,19 +289,19 @@ public ByteBuffer appendHex(byte b) {
289289
* Appends a string representation of a <CODE>float</CODE> according
290290
* to the Pdf conventions.
291291
* @param i the <CODE>float</CODE> to be appended
292-
* @return a reference to this <CODE>ByteBuffer</CODE> object
292+
* @return a reference to this <CODE>ByteBufferOutputStream</CODE> object
293293
*/
294-
public ByteBuffer append(float i) {
294+
public ByteBufferOutputStream append(float i) {
295295
return append((double)i);
296296
}
297297

298298
/**
299299
* Appends a string representation of a <CODE>double</CODE> according
300300
* to the Pdf conventions.
301301
* @param d the <CODE>double</CODE> to be appended
302-
* @return a reference to this <CODE>ByteBuffer</CODE> object
302+
* @return a reference to this <CODE>ByteBufferOutputStream</CODE> object
303303
*/
304-
public ByteBuffer append(double d) {
304+
public ByteBufferOutputStream append(double d) {
305305
append(formatDouble(d, this));
306306
return this;
307307
}
@@ -318,12 +318,12 @@ public static String formatDouble(double d) {
318318
/**
319319
* Outputs a <CODE>double</CODE> into a format suitable for the PDF.
320320
* @param d a double
321-
* @param buf a ByteBuffer
321+
* @param buf a ByteBufferOutputStream
322322
* @return the <CODE>String</CODE> representation of the <CODE>double</CODE> if
323323
* <CODE>buf</CODE> is <CODE>null</CODE>. If <CODE>buf</CODE> is <B>not</B> <CODE>null</CODE>,
324324
* then the double is appended directly to the buffer and this methods returns <CODE>null</CODE>.
325325
*/
326-
public static String formatDouble(double d, ByteBuffer buf) {
326+
public static String formatDouble(double d, ByteBufferOutputStream buf) {
327327
if (HIGH_PRECISION) {
328328
DecimalFormat dn = new DecimalFormat("0.######", dfs);
329329
String sform = dn.format(d);

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

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -495,15 +495,15 @@ static class ByteStore {
495495
private final byte[] b;
496496
private final int hash;
497497
private MessageDigest md5;
498-
private void serObject(PdfObject obj, int level, ByteBuffer bb, HashMap<Integer, Integer> serialized) {
498+
private void serObject(PdfObject obj, int level, ByteBufferOutputStream bb, HashMap<Integer, Integer> serialized) {
499499
if (level <= 0)
500500
return;
501501
if (obj == null) {
502502
bb.append("$Lnull");
503503
return;
504504
}
505505
PdfIndirectReference ref = null;
506-
ByteBuffer savedBb = null;
506+
ByteBufferOutputStream savedBb = null;
507507

508508
if (obj.isIndirectReference()) {
509509
ref = (PdfIndirectReference)obj;
@@ -514,7 +514,7 @@ private void serObject(PdfObject obj, int level, ByteBuffer bb, HashMap<Integer,
514514
}
515515
else {
516516
savedBb = bb;
517-
bb = new ByteBuffer();
517+
bb = new ByteBufferOutputStream();
518518
}
519519
}
520520

@@ -549,22 +549,22 @@ else if (obj.isName()) {
549549
}
550550
}
551551

552-
private void serDic(PdfDictionary dic, int level, ByteBuffer bb, HashMap<Integer, Integer> serialized) {
552+
private void serDic(PdfDictionary dic, int level, ByteBufferOutputStream bb, HashMap<Integer, Integer> serialized) {
553553
bb.append("$D");
554554
if (level <= 0)
555555
return;
556556
Object[] keys = dic.keySet().toArray();
557557
Arrays.sort(keys);
558-
for (int k = 0; k < keys.length; ++k) {
559-
if(keys[k].equals(PdfName.P) &&(dic.get((PdfName)keys[k]).isIndirectReference() || dic.get((PdfName)keys[k]).isDictionary()) || keys[k].equals(PdfName.Parent)) // ignore recursive call
558+
for (Object key : keys) {
559+
if (key.equals(PdfName.P) && (dic.get((PdfName) key).isIndirectReference() || dic.get((PdfName) key).isDictionary()) || key.equals(PdfName.Parent)) // ignore recursive call
560560
continue;
561-
serObject((PdfObject) keys[k], level, bb, serialized);
562-
serObject(dic.get((PdfName) keys[k], false), level, bb, serialized);
561+
serObject((PdfObject) key, level, bb, serialized);
562+
serObject(dic.get((PdfName) key, false), level, bb, serialized);
563563

564564
}
565565
}
566566

567-
private void serArray(PdfArray array, int level, ByteBuffer bb, HashMap<Integer, Integer> serialized) {
567+
private void serArray(PdfArray array, int level, ByteBufferOutputStream bb, HashMap<Integer, Integer> serialized) {
568568
bb.append("$A");
569569
if (level <= 0)
570570
return;
@@ -580,7 +580,7 @@ private void serArray(PdfArray array, int level, ByteBuffer bb, HashMap<Integer,
580580
catch (Exception e) {
581581
throw new PdfException(e);
582582
}
583-
ByteBuffer bb = new ByteBuffer();
583+
ByteBufferOutputStream bb = new ByteBufferOutputStream();
584584
int level = 100;
585585
serObject(str, level, bb, serialized);
586586
this.b = bb.toByteArray();
@@ -595,7 +595,7 @@ private void serArray(PdfArray array, int level, ByteBuffer bb, HashMap<Integer,
595595
catch (Exception e) {
596596
throw new PdfException(e);
597597
}
598-
ByteBuffer bb = new ByteBuffer();
598+
ByteBufferOutputStream bb = new ByteBufferOutputStream();
599599
int level = 100;
600600
serObject(dict, level, bb, serialized);
601601
this.b = bb.toByteArray();
@@ -606,18 +606,16 @@ private void serArray(PdfArray array, int level, ByteBuffer bb, HashMap<Integer,
606606
private static int calculateHash(byte[] b) {
607607
int hash = 0;
608608
int len = b.length;
609-
for (int k = 0; k < len; ++k)
609+
for (int k = 0; k < len; ++k) {
610610
hash = hash * 31 + (b[k] & 0xff);
611+
}
611612
return hash;
612613
}
613614

614615
@Override
615616
public boolean equals(Object obj) {
616-
if (!(obj instanceof ByteStore))
617-
return false;
618-
if (hashCode() != obj.hashCode())
619-
return false;
620-
return Arrays.equals(b, ((ByteStore)obj).b);
617+
return obj instanceof ByteStore &&
618+
hashCode() == obj.hashCode() && Arrays.equals(b, ((ByteStore) obj).b);
621619
}
622620

623621
@Override

0 commit comments

Comments
 (0)