public class ByteBufferOutputStream extends OutputStream
StringBuffer
but works with byte
arrays. Floating point is converted to a format suitable to the PDF.
Modifier and Type | Field and Description |
---|---|
protected byte[] |
buf
The buffer where the bytes are stored.
|
protected int |
count
The count of bytes in the buffer.
|
static boolean |
HIGH_PRECISION
If true always output floating point numbers with 6 decimal digits.
|
static byte |
ZERO |
Constructor and Description |
---|
ByteBufferOutputStream()
Creates new ByteBufferOutputStream with capacity 128
|
ByteBufferOutputStream(int size)
Creates a byte buffer with a certain capacity.
|
Modifier and Type | Method and Description |
---|---|
ByteBufferOutputStream |
append_i(int b)
Appends an int .
|
ByteBufferOutputStream |
append(byte b) |
ByteBufferOutputStream |
append(byte[] b)
Appends an array of bytes.
|
ByteBufferOutputStream |
append(byte[] b, int off, int len)
Appends the subarray of the byte array.
|
ByteBufferOutputStream |
append(ByteBufferOutputStream buf)
Appends another ByteBufferOutputStream to this buffer.
|
ByteBufferOutputStream |
append(char c)
Appends a char to the buffer.
|
ByteBufferOutputStream |
append(double d)
Appends a string representation of a double according to the Pdf conventions.
|
ByteBufferOutputStream |
append(float i)
Appends a string representation of a float according to the Pdf conventions.
|
ByteBufferOutputStream |
append(int i)
Appends the string representation of an int .
|
ByteBufferOutputStream |
append(long i)
Appends the string representation of a long .
|
ByteBufferOutputStream |
append(String str)
Appends a String to the buffer.
|
ByteBufferOutputStream |
appendHex(byte b) |
static void |
fillCache(int decimals)
You can fill the cache in advance if you want to.
|
static String |
formatDouble(double d)
Outputs a double into a format suitable for the PDF.
|
static String |
formatDouble(double d, ByteBufferOutputStream buf)
Outputs a double into a format suitable for the PDF.
|
byte[] |
getBuffer() |
void |
reset()
Sets the size to zero.
|
static void |
setCacheSize(int size)
Sets the cache size.
|
void |
setSize(int size) |
int |
size()
Returns the current size of the buffer.
|
byte[] |
toByteArray()
Creates a newly allocated byte array.
|
String |
toString()
Converts the buffer's contents into a string, translating bytes into characters according to the platform's default character encoding.
|
String |
toString(String enc)
Converts the buffer's contents into a string, translating bytes into characters according to the specified character encoding.
|
void |
write(byte[] b, int off, int len) |
void |
write(int b) |
void |
writeTo(OutputStream output)
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 using out.write(buf, 0, count) .
|
close, flush, write
public static final byte ZERO
public static boolean HIGH_PRECISION
true
always output floating point numbers with 6 decimal digits. If false
uses the faster, although less precise, representation.
protected int count
protected byte[] buf
public ByteBufferOutputStream()
public ByteBufferOutputStream(int size)
size
- the initial capacity
public static void setCacheSize(int size)
This can only be used to increment the size. If the size that is passed through is smaller than the current size, nothing happens.
size
- the size of the cache
public static void fillCache(int decimals)
decimals
-
public static String formatDouble(double d)
double
into a format suitable for the PDF.
d
- a double
String
representation of the double
public static String formatDouble(double d, ByteBufferOutputStream buf)
double
into a format suitable for the PDF.
d
- a double
buf
- a ByteBufferOutputStream
String
representation of the double
if buf
is null
. If buf
is not null
, then the double is appended directly to the buffer and this methods returns null
.
public ByteBufferOutputStream append_i(int b)
int
. The size of the array will grow by one.
b
- the int to be appended
ByteBufferOutputStream
object
public ByteBufferOutputStream append(byte[] b, int off, int len)
byte
array. The buffer will grow by len
bytes.
b
- the array to be appended
off
- the offset to the start of the array
len
- the length of bytes to append
ByteBufferOutputStream
object
public ByteBufferOutputStream append(byte[] b)
b
- the array to be appended
ByteBufferOutputStream
object
public ByteBufferOutputStream append(String str)
String
to the buffer. The String
is converted according to the encoding ISO-8859-1.
str
- the String
to be appended
ByteBufferOutputStream
object
public ByteBufferOutputStream append(char c)
char
to the buffer. The char
is converted according to the encoding ISO-8859-1.
c
- the char
to be appended
ByteBufferOutputStream
object
public ByteBufferOutputStream append(ByteBufferOutputStream buf)
ByteBufferOutputStream
to this buffer.
buf
- the ByteBufferOutputStream
to be appended
ByteBufferOutputStream
object
public ByteBufferOutputStream append(int i)
int
.
i
- the int
to be appended
ByteBufferOutputStream
object
public ByteBufferOutputStream append(long i)
long
.
i
- the long
to be appended
ByteBufferOutputStream
object
public ByteBufferOutputStream append(byte b)
public ByteBufferOutputStream appendHex(byte b)
public ByteBufferOutputStream append(float i)
float
according to the Pdf conventions.
i
- the float
to be appended
ByteBufferOutputStream
object
public ByteBufferOutputStream append(double d)
double
according to the Pdf conventions.
d
- the double
to be appended
ByteBufferOutputStream
object
public void reset()
public byte[] toByteArray()
public int size()
count
field, which is the number of valid bytes in this byte buffer.
public void setSize(int size)
public String toString()
public String toString(String enc) throws UnsupportedEncodingException
enc
- a character-encoding name.
UnsupportedEncodingException
- If the named encoding is not supported.
public void writeTo(OutputStream output) throws IOException
out.write(buf, 0, count)
.
output
- the output stream to which to write the data.
IOException
- if an I/O error occurs.
public void write(int b) throws IOException
write
in class OutputStream
IOException
public void write(byte[] b, int off, int len)
write
in class OutputStream
public byte[] getBuffer()
Copyright © 1998–2017 iText Group NV. All rights reserved.