public class FastByteArrayOutputStream extends OutputStream
The data can be retrieved using toByteArray() and
toString().
Closing a FastByteArrayOutputStream has no effect. The methods
in this class can be called after the stream has been closed without
generating an IOException.
This is an alternative implementation of the java.io.FastByteArrayOutputStream class. The original implementation only allocates 32 bytes at the beginning. As this class is designed for heavy duty it starts at 1024 bytes. In contrast to the original it doesn't reallocate the whole memory block but allocates additional buffers. This way no buffers need to be garbage collected and the contents don't have to be copied to the new buffer. This class is designed to behave exactly like the original. The only exception is the depreciated toString(int) method that has been ignored.
| Constructor and Description |
|---|
FastByteArrayOutputStream()
Creates a new byte array output stream.
|
FastByteArrayOutputStream(int size)
Creates a new byte array output stream, with a buffer capacity of the
specified size, in bytes.
|
| Modifier and Type | Method and Description |
|---|---|
void |
close()
Closing a
FastByteArrayOutputStream has no effect. |
void |
reset()
Reset.
|
int |
size()
Size.
|
byte[] |
toByteArray()
To byte array.
|
String |
toString()
To string.
|
String |
toString(String enc)
To string.
|
void |
write(byte[] b,
int off,
int len)
Write.
|
void |
write(int b)
Writes single byte.
|
void |
writeTo(OutputStream out)
Write to.
|
flush, writepublic FastByteArrayOutputStream()
public FastByteArrayOutputStream(int size)
size - the initial size.public void write(byte[] b,
int off,
int len)
write in class OutputStreamb - the boff - the offlen - the lenOutputStream.write(byte[], int, int)public void write(int b)
write in class OutputStreamb - the bpublic int size()
ByteArrayOutputStream.size()public void close()
FastByteArrayOutputStream has no effect. The
methods in this class can be called after the stream has been closed
without generating an IOException.close in interface Closeableclose in interface AutoCloseableclose in class OutputStreampublic void reset()
ByteArrayOutputStream.reset()public void writeTo(OutputStream out) throws IOException
out - the outIOException - Signals that an I/O exception has occurred.ByteArrayOutputStream.writeTo(OutputStream)public byte[] toByteArray()
ByteArrayOutputStream.toByteArray()public String toString()
toString in class ObjectByteArrayOutputStream.toString()public String toString(String enc) throws UnsupportedEncodingException
enc - the encUnsupportedEncodingException - the unsupported encoding exceptionByteArrayOutputStream.toString(String)Copyright © 2016 utils4j. All Rights Reserved.