Package org.openpdf.text.pdf
Class ByteBuffer
java.lang.Object
java.io.OutputStream
org.openpdf.text.pdf.ByteBuffer
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
Acts like a
StringBuffer but works with byte arrays. Floating point is converted to a
format suitable to the PDF.-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected byte[]The buffer where the bytes are stored.protected intThe count of bytes in the buffer.static booleanIftruealways output floating point numbers with 6 decimal digits.static final byte -
Constructor Summary
ConstructorsConstructorDescriptionCreates new ByteBuffer with capacity 128ByteBuffer(int size) Creates a byte buffer with a certain capacity. -
Method Summary
Modifier and TypeMethodDescriptionappend(byte b) append(byte[] b) Appends an array of bytes.append(byte[] b, int off, int len) Appends the subarray of thebytearray.append(char c) Appends acharto the buffer.append(double d) Appends a string representation of adoubleaccording to the Pdf conventions.append(float i) Appends a string representation of afloataccording to the Pdf conventions.append(int i) Appends the string representation of anint.Appends aStringto the buffer.append(ByteBuffer buf) Appends anotherByteBufferto this buffer.append_i(int b) Appends anint.appendHex(byte b) static StringformatDouble(double d) Outputs adoubleinto a format suitable for the PDF.static StringformatDouble(double d, ByteBuffer buf) Outputs adoubleinto a format suitable for the PDF.voidreset()Sets the size to zero.intsize()Returns the current size of the buffer.byte[]Creates a newly allocated byte array.toString()Converts the buffer's contents into a string, translating bytes into characters according to the platform's default character encoding.voidwrite(byte[] b, int off, int len) voidwrite(int b) voidwriteTo(OutputStream out) Writes the complete contents of this byte buffer output to the specified output stream argument, as if by calling the output stream's write method usingout.write(buf, 0, count).Methods inherited from class java.io.OutputStream
close, flush, nullOutputStream, write
-
Field Details
-
ZERO
public static final byte ZERO- See Also:
-
HIGH_PRECISION
public static boolean HIGH_PRECISIONIftruealways output floating point numbers with 6 decimal digits. Iffalseuses the faster, although less precise, representation. -
count
protected int countThe count of bytes in the buffer. -
buf
protected byte[] bufThe buffer where the bytes are stored.
-
-
Constructor Details
-
ByteBuffer
public ByteBuffer()Creates new ByteBuffer with capacity 128 -
ByteBuffer
public ByteBuffer(int size) Creates a byte buffer with a certain capacity.- Parameters:
size- the initial capacity
-
-
Method Details
-
formatDouble
Outputs adoubleinto a format suitable for the PDF.- Parameters:
d- a double- Returns:
- the
Stringrepresentation of thedouble
-
formatDouble
Outputs adoubleinto a format suitable for the PDF.- Parameters:
d- a doublebuf- a ByteBuffer- Returns:
- the
Stringrepresentation of thedoubleifbufisnull. Ifbufis notnull, then the double is appended directly to the buffer and this methods returnsnull.
-
append_i
Appends anint. The size of the array will grow by one.- Parameters:
b- the int to be appended- Returns:
- a reference to this
ByteBufferobject
-
append
Appends the subarray of thebytearray. The buffer will grow bylenbytes.- Parameters:
b- the array to be appendedoff- the offset to the start of the arraylen- the length of bytes to append- Returns:
- a reference to this
ByteBufferobject
-
append
Appends an array of bytes.- Parameters:
b- the array to be appended- Returns:
- a reference to this
ByteBufferobject
-
append
Appends aStringto the buffer. TheStringis converted according to the encoding ISO-8859-1.- Parameters:
str- theStringto be appended- Returns:
- a reference to this
ByteBufferobject
-
append
Appends acharto the buffer. Thecharis converted according to the encoding ISO-8859-1.- Parameters:
c- thecharto be appended- Returns:
- a reference to this
ByteBufferobject
-
append
Appends anotherByteBufferto this buffer.- Parameters:
buf- theByteBufferto be appended- Returns:
- a reference to this
ByteBufferobject
-
append
Appends the string representation of anint.- Parameters:
i- theintto be appended- Returns:
- a reference to this
ByteBufferobject
-
append
-
appendHex
-
append
Appends a string representation of afloataccording to the Pdf conventions.- Parameters:
i- thefloatto be appended- Returns:
- a reference to this
ByteBufferobject
-
append
Appends a string representation of adoubleaccording to the Pdf conventions.- Parameters:
d- thedoubleto be appended- Returns:
- a reference to this
ByteBufferobject
-
reset
public void reset()Sets the size to zero. -
toByteArray
public byte[] toByteArray()Creates a newly allocated byte array. Its size is the current size of this output stream and the valid contents of the buffer have been copied into it.- Returns:
- the current contents of this output stream, as a byte array.
-
size
public int size()Returns the current size of the buffer.- Returns:
- the value of the
countfield, which is the number of valid bytes in this byte buffer.
-
toString
Converts the buffer's contents into a string, translating bytes into characters according to the platform's default character encoding. -
writeTo
Writes the complete contents of this byte buffer output to the specified output stream argument, as if by calling the output stream's write method usingout.write(buf, 0, count).- Parameters:
out- the output stream to which to write the data.- Throws:
IOException- if an I/O error occurs.
-
write
public void write(int b) - Specified by:
writein classOutputStream
-
write
public void write(byte[] b, int off, int len) - Overrides:
writein classOutputStream
-