Package org.jppf.utils.streams
Class JPPFByteArrayOutputStream
java.lang.Object
java.io.OutputStream
java.io.ByteArrayOutputStream
org.jppf.utils.streams.JPPFByteArrayOutputStream
- All Implemented Interfaces:
Closeable,Flushable,AutoCloseable
Extension of
ByteArrayOutputStream, providing
a faster toByteArray() method that does not involve copying its internal buffer.- Author:
- Laurent Cohen
-
Field Summary
Fields inherited from class java.io.ByteArrayOutputStream
buf, count -
Constructor Summary
ConstructorsConstructorDescriptionInstantiate this stream with a default size.JPPFByteArrayOutputStream(int size) Instantiate this stream with the specified size. -
Method Summary
Modifier and TypeMethodDescriptionbyte[]getBuf()Provide access to the internal buffer.byte[]Override oftoByteArray()that returns a reference to the internal buffer instead of copy of it, significantly increasing the performance of this operation.Methods inherited from class java.io.ByteArrayOutputStream
close, reset, size, toString, toString, toString, toString, write, write, writeBytes, writeToMethods inherited from class java.io.OutputStream
flush, nullOutputStream, write
-
Constructor Details
-
JPPFByteArrayOutputStream
public JPPFByteArrayOutputStream()Instantiate this stream with a default size. -
JPPFByteArrayOutputStream
public JPPFByteArrayOutputStream(int size) Instantiate this stream with the specified size.- Parameters:
size- the initial size of the underlying buffer.
-
-
Method Details
-
toByteArray
public byte[] toByteArray()Override oftoByteArray()that returns a reference to the internal buffer instead of copy of it, significantly increasing the performance of this operation.- Overrides:
toByteArrayin classByteArrayOutputStream- Returns:
- the content of the stream as an array of bytes.
- See Also:
-
getBuf
public byte[] getBuf()Provide access to the internal buffer.- Returns:
- an array of bytes.
-