ByteArrayOutputStream

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.

Author

Arthur van Hoff

Since

1.0

Constructors

Link copied to clipboard
constructor(size: Int = 32)

Functions

Link copied to clipboard
open override fun close()

Closing a ByteArrayOutputStream has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.

Link copied to clipboard
open override fun flush()

Flushes this output stream and forces any buffered output bytes to be written out. The general contract of flush is that calling it is an indication that, if any bytes previously written have been buffered by the implementation of the output stream, such bytes should immediately be written to their intended destination.

Link copied to clipboard
fun reset()

Resets the count field of this ByteArrayOutputStream to zero, so that all currently accumulated output in the output stream is discarded. The output stream can be used again, reusing the already allocated buffer space.

Link copied to clipboard
fun size(): Int

Returns the current size of the buffer.

Link copied to clipboard

Creates a newly allocated byte array. Its size is the current size of this output stream and the valid contents of the buffer have been copied into it.

Link copied to clipboard
open override fun toString(): String

Converts the buffer's contents into a string decoding bytes using the default charset. The length of the new String is a function of the charset, and hence may not be equal to the size of the buffer.

fun toString(charsetName: String): String

Converts the buffer's contents into a string by decoding the bytes using the named charset.

fun toString(charset: Charset): String

Converts the buffer's contents into a string by decoding the bytes using the specified charset. The length of the new String is a function of the charset, and hence may not be equal to the length of the byte array.

Link copied to clipboard
open override fun write(b: Int)

Writes the specified byte to this ByteArrayOutputStream.

open override fun write(b: ByteArray, off: Int, len: Int)

Writes len bytes from the specified byte array starting at offset off to this ByteArrayOutputStream.

open fun write(b: ByteArray)

Writes b.length bytes from the specified byte array to this output stream. The general contract for write(b) is that it should have exactly the same effect as the call write(b, 0, b.length).

Link copied to clipboard

Writes the complete contents of the specified byte array to this ByteArrayOutputStream.

Link copied to clipboard

Writes the complete contents of this ByteArrayOutputStream to the specified output stream argument, as if by calling the output stream's write method using out.write(buf, 0, count).