java.lang.Object | ||
↳ | java.io.OutputStream | |
↳ | java.io.ByteArrayOutputStream |
A specialized OutputStream
for class for writing content to an
(internal) byte array. As bytes are written to this stream, the byte array
may be expanded to hold more bytes. When the writing is considered to be
finished, a copy of the byte array can be requested from the class.
Fields | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
buf | The byte array containing the bytes written. | ||||||||||
count | The number of bytes written. |
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new ByteArrayOutputStream with a default size of 32 bytes.
| |||||||||||
Constructs a new
ByteArrayOutputStream with a default size of
size bytes. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Closes this stream.
| |||||||||||
Resets this stream to the beginning of the underlying byte array.
| |||||||||||
Returns the total number of bytes written to this stream so far.
| |||||||||||
Returns the contents of this ByteArrayOutputStream as a byte array.
| |||||||||||
Returns the contents of this ByteArrayOutputStream as a string.
| |||||||||||
Returns the contents of this ByteArrayOutputStream as a string converted
according to the encoding declared in
enc . | |||||||||||
This method is deprecated.
Use
toString() .
| |||||||||||
Writes the specified byte
oneByte to the OutputStream. | |||||||||||
Writes
count bytes from the byte array buffer starting at
offset index to this stream. | |||||||||||
Takes the contents of this stream and writes it to the output stream
out . |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.io.OutputStream
| |||||||||||
From class java.lang.Object
| |||||||||||
From interface java.io.Closeable
| |||||||||||
From interface java.io.Flushable
|
Constructs a new ByteArrayOutputStream with a default size of 32 bytes. If more than 32 bytes are written to this instance, the underlying byte array will expand.
Constructs a new ByteArrayOutputStream
with a default size of
size
bytes. If more than size
bytes are written to this
instance, the underlying byte array will expand.
size | initial size for the underlying byte array, must be non-negative. |
---|
IllegalArgumentException | if size < 0.
|
---|
Closes this stream. This releases system resources used for this stream.
IOException | if an error occurs while attempting to close this stream. |
---|
Resets this stream to the beginning of the underlying byte array. All subsequent writes will overwrite any bytes previously stored in this stream.
Returns the total number of bytes written to this stream so far.
Returns the contents of this ByteArrayOutputStream as a byte array. Any changes made to the receiver after returning will not be reflected in the byte array returned to the caller.
Returns the contents of this ByteArrayOutputStream as a string. Any changes made to the receiver after returning will not be reflected in the string returned to the caller.
Returns the contents of this ByteArrayOutputStream as a string converted
according to the encoding declared in enc
.
enc | a string representing the encoding to use when translating this stream to a string. |
---|
UnsupportedEncodingException | if the provided encoding is not supported. |
---|
This method is deprecated.
Use toString()
.
Returns the contents of this ByteArrayOutputStream as a string. Each byte
b
in this stream is converted to a character c
using the
following function:
c == (char)(((hibyte & 0xff) << 8) | (b & 0xff))
. This method is
deprecated and either toString()
or toString(String)
should be used.
hibyte | the high byte of each resulting Unicode character. |
---|
hibyte
.Writes the specified byte oneByte
to the OutputStream. Only the
low order byte of oneByte
is written.
oneByte | the byte to be written. |
---|
Writes count
bytes from the byte array buffer
starting at
offset index
to this stream.
buffer | the buffer to be written. |
---|---|
offset | the initial position in buffer to retrieve bytes. |
len | the number of bytes of buffer to write. |
NullPointerException | if buffer is null . |
---|---|
IndexOutOfBoundsException | if offset < 0 or len < 0 , or if
offset + len is greater than the length of
buffer .
|
Takes the contents of this stream and writes it to the output stream
out
.
out | an OutputStream on which to write the contents of this stream. |
---|
IOException | if an error occurs while writing to out .
|
---|