The class also contains more functions for more complex manipulations.
For writing structured data to the stream, use the subclass DataOutputUnsyncByteArrayOutputStream.
protected byte[] | The buffer that holds the bytes. |
protected int | The number of valid data in the buffer. |
public | Creates a new instance with the default buffer size of 128. |
public | UnsyncByteArrayOutputStream( Creates a new instance with the argument buffer size. |
public | UnsyncByteArrayOutputStream( Creates a new instance that is directly backed by the argument buffer, and currently contains count
number of valid bytes. |
public void | close() Closes this output stream and releases any system resources
associated with this stream. |
public void | ensureCapacity( Grows the internal buffer of the stream to be able to hold the specified amount of bytes. |
public byte[] | Gets the current backing buffer of the stream. |
public int | Gets the current maximum number of bytes the stream can hold. |
public int | indexOf( Gets the first occurrence of a byte value in the stream. |
public int | indexOf( Gets the first occurrence of a byte after a given offset. |
public boolean | isEmpty() Checks if the stream currently holds any bytes. |
public int | lastIndexOf( Gets the last occurrence of a byte in the stream. |
public int | lastIndexOf( Gets the last occurrence of a byte after a given offset. |
public long | readFrom( Reads bytes from the argument input stream until no more bytes are available. |
public int | readFrom( Reads at most the given number of bytes from the input stream. |
public long | readFrom( Reads bytes from the argument byte source and writes it to this byte sink. |
public int | readFrom( Reads at most the given number of bytes from the byte source. |
public void | reduceSize( Reduces the number of valid bytes in the stream. |
public void | repeat( Appends the same byte data to the stream multiple times. |
public void | replaceByte( Replaces a byte in the stream at the given offset. |
public void | reset() Resets the stream to hold 0 bytes. |
public int | size() Gets the current number of valid bytes in the stream. |
public byte[] | Gets the currently present data in the stream in a newly allocated array. |
public ByteArrayRegion | Converts the current data buffer to a ByteArrayRegion. |
public String | toString() Converts the current contents of the stream to a string representation by decoding it using UTF-8. |
public String | toString( Converts the specified region of data of the stream to a string representation by decoding it using UTF-8. |
public String | Converts the specified region of data of the stream to a string representation by decoding it using the argument
charset. |
public String | Converts the current contents of the stream to string representation by decoding it using the argument charset. |
public void | write( Writes the specified byte to this output stream. |
public int | write( Copies the contets of the argument byte buffer to this output stream. |
public void | write( Writes the bytes contained in the argument byte array to the byte sink. |
public void | write( Writes b.length bytes from the specified byte array
to this output stream. |
public void | write( Writes len bytes from the specified byte array
starting at offset off to this output stream. |
public void | writeTo( Writes the current contents of the stream to the argument. |
public void | writeTo( Writes a region of the current contents of the stream to the argument. |
public void | writeTo( Writes the current contents of the stream to the argument. |
public void | writeTo( Writes a region of the current contents of the stream to the argument. |
public void | writeTo( Writes the current contents of the stream to the argument. |
public void | writeTo( Writes a region of the current contents of the stream to the argument. |
public long | Writes the current contents of the stream to the argument. |
public void | Writes a region of the current contents of the stream to the argument. |
This means that the region 0..count
contains valid bytes.
count
number of valid bytes. If more bytes are written to the stream, it may grow accordingly.
close
is that it closes the output stream. A closed stream cannot perform
output operations and cannot be reopened.
The close
method of OutputStream
does nothing.
Any modifications made to the elements of the returned array may be propagated back to the stream. No copy is made.
The capacity of
true
if the stream is empty.null
.count
if there were no more available
bytes in the input stream.null
.this
byte sink. This method will possibly read all bytes from the argument byte source and all the read bytes will be written to this byte sink. If the argument is a blocking source, then this method will block too.
Calling this method instead of copying the bytes externally can have advantages, as implementations can read the bytes into an internal buffer more efficiently, therefore avoiding unnecessary copying and allocations.
The default implementation calls ByteSource.writeTo(
count
if there were no more available
bytes in the byte source.null
.This method discards bytes from the end of the valid bytes region in the internal buffer. The array size of the internal buffer is unaffected. Only the number of valid bytes are modified in the stream.
This method can be used to throw away some written bytes from the stream.
Only the lowest 8 bits of the argument value is used.
The capacity and the size of the stream is modified accordingly, so the offset will always point to a valid region. The buffer size and the valid number of bytes will be the maximum of the current size, and offset + 1.
Any current bytes in the stream are discarded.
The current data stored in the stream is not overwritten.
This method is named size
instead of getSize
, to be aligned with the
ByteArrayOutputStream.size() function naming.
The returned array has the same length as the number of valid bytes in the stream.
The returned byte array region is backed by the internal buffer of the stream. Any modifications made to the returned array may (but not necessarily) propagate back to the stream.
If any operations are called on the stream after this method returns, the modifications might not propagate back, as the internal buffer may be reallocated.
write
is that one byte is written
to the output stream. The byte to be written is the eight
low-order bits of the argument b
. The 24
high-order bits of b
are ignored.
Subclasses of OutputStream
must provide an
implementation for this method.
byte
.The number of bytes copied equals to Buffer.remaining().
null
.
This method works similarly to OutputStream.write(
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)
.len
bytes from the specified byte array
starting at offset off
to this output stream. The general contract for write(b, off, len)
is that
some of the bytes in the array b
are written to the
output stream in order; element b[off]
is the first
byte written and b[off+len-1]
is the last byte written
by this operation.
The write
method of OutputStream
calls
the write method of one argument on each of the bytes to be
written out. Subclasses are encouraged to override this method and
provide a more efficient implementation.
If b
is null
, a
NullPointerException
is thrown.
If off
is negative, or len
is negative, or
off+len
is greater than the length of the array
b
, then an IndexOutOfBoundsException is thrown.
offset + len > size() || offset < 0
.offset + len > size() || offset < 0
.offset + len > size() || offset < 0
.
This method returns the number of bytes written to the stream to have the method signature be compatible with
ByteSource.writeTo(
offset + len > size() || offset < 0
.