public class FastByteArrayOutputStream extends OutputStream
The idea for such an implementation was originally obtained from Berkeley DB JE, however, this represents a clean-room implementation that is NOT derived from their implementation for license reasons and differs in implementation considerably. For compatibility reasons we have tried to conserve the interface as much as possible.
| Modifier and Type | Field and Description |
|---|---|
protected byte[] |
buf
The Buf.
|
protected int |
count
The Count.
|
static int |
DEFAULT_SIZE
The constant DEFAULT_SIZE.
|
| Constructor and Description |
|---|
FastByteArrayOutputStream()
Create a new FastByteArrayOutputStream.
|
FastByteArrayOutputStream(byte[] buf)
Create a new FastByteArrayOutputStream with a given
initial buffer.
|
FastByteArrayOutputStream(int bufferSize)
Create a new FastByteArrayOutputStream with a given
initial buffer size.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closing a FastByteArrayOutputStream has no effect.
|
void |
ensureCapacity(int minCapacity)
Increases the capacity of this FastByteArrayOutputStreams buffer,
if necessary, to ensure that it can hold at least the number of
bytes specified by the minimum capacity argument.
|
byte[] |
getBuffer()
Returns a reference to the buffer of this
FastByteArrayOutputStream.
|
void |
reset()
Resets the count of this FastByteArrayOutputStream
to zero, so that all currently accumulated output in the
ouput stream is discarded when overwritten.
|
int |
size()
Returns the current number of bytes in the buffer of this
FastByteArrayOutputStream.
|
byte[] |
toByteArray()
Returns a newly allocated byte[] with the actual content
of the buffer of this FastByteArrayOutputStream.
|
void |
toByteArray(byte[] b,
int offset)
Copies the content of this FastByteArrayOutputStream
into the given byte array, starting from the given offset.
|
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[] buf)
Convenience method that writes all bytes from the specified byte
array to this FastByteArrayOutputStream.
|
void |
write(byte[] b,
int off,
int len)
Writes len bytes from the specified byte array starting at offset off
to this FastByteArrayOutputStream.
|
void |
write(int b)
Writes the specified byte to this byte array output stream.
|
void |
writeTo(OutputStream out)
Writes the complete contents of this FastByteArrayOutputStream to
the specified output stream argument.
|
flushprotected int count
protected byte[] buf
public static final int DEFAULT_SIZE
public FastByteArrayOutputStream()
DEFAULT_SIZE will be used.public FastByteArrayOutputStream(int bufferSize)
bufferSize - the initial size of the buffer as int.public FastByteArrayOutputStream(byte[] buf)
buf - the buffer as byte[].public void close()
close in interface Closeableclose in interface AutoCloseableclose in class OutputStreampublic void reset()
public int size()
public byte[] toByteArray()
#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 write(byte[] b,
int off,
int len)
write in class OutputStreamb - the data.off - the start offset in the data.len - the number of bytes to write.public void write(int b)
write in class OutputStreamb - the byte to be written.public void writeTo(OutputStream out) throws IOException
out - the output stream to which to write the data.IOException - if an I/O error occurs.public void write(byte[] buf)
throws IOException
write in class OutputStreambuf - the bufferIOException - the exceptionpublic final void ensureCapacity(int minCapacity)
minCapacity - the desired minimum capacity.public void toByteArray(byte[] b,
int offset)
b - the buffer to hold a copy of the data.offset - the offset at which to start copying.public byte[] getBuffer()
Copyright © 2017. All rights reserved.