open class ByteArrayOutputStream : OutputStream
This class implements an output stream in which the data is written into a byte array. The buffer automatically grows as data is written to it.
The data can be retrieved using toByteArray()
and toString()
.
Closing a ByteArrayOutputStream 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.ByteArrayOutputStream 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 deprecated toString(int) method that has been ignored.
Author
Jeremias Maerki
Author
Holger Hoffstatte
Version
$Id: ByteArrayOutputStream.java 491007 2006-12-29 13:50:34Z scolebourne $
ByteArrayOutputStream()
Creates a new byte array output stream. The buffer capacity is initially 1024 bytes, though its size increases if necessary. ByteArrayOutputStream(size: Int)
Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes. |
open fun close(): Unit
Closing a ByteArrayOutputStream has no effect. The methods in this class can be called after the stream has been closed without generating an IOException. |
|
open fun reset(): Unit |
|
open fun size(): Int |
|
open fun toByteArray(): ByteArray!
Gets the curent contents of this byte stream as a byte array. The result is independent of this stream. |
|
open fun toString(): String
Gets the curent contents of this byte stream as a string. open fun toString(enc: String!): String!
Gets the curent contents of this byte stream as a string using the specified encoding. |
|
open fun write(b: ByteArray!, off: Int, len: Int): Unit open fun write(b: Int): Unit |
|
open fun writeTo(out: OutputStream!): Unit
Writes the entire contents of this byte stream to the specified output stream. |