Class java.io.ByteArrayOutputStream
All Packages Class Hierarchy This Package Previous Next Index
Class java.io.ByteArrayOutputStream
java.lang.Object
|
+----java.io.OutputStream
|
+----java.io.ByteArrayOutputStream
- public class ByteArrayOutputStream
- extends OutputStream
This class implements a buffer that can be
used as an OutputStream. The buffer automatically
grows when data is written to the stream.
The data can be retrieved using toByteArray() and
toString().
- buf
- The buffer where data is stored.
- count
- The number of bytes in the buffer.
- ByteArrayOutputStream()
- Creates a new ByteArrayOutputStream.
- ByteArrayOutputStream(int)
- Creates a new ByteArrayOutputStream with the specified initial size.
- reset()
- Resets the buffer so that you can use it again without
throwing away the already allocated buffer.
- size()
- Returns the current size of the buffer.
- toByteArray()
- Returns a copy of the input data.
- toString()
- Converts input data to a string.
- toString(int)
- Converts input data to a string.
- write(byte[], int, int)
- Writes bytes to the buffer.
- write(int)
- Writes a byte to the buffer.
- writeTo(OutputStream)
- Writes the contents of the buffer to another stream.
buf
protected byte buf[]
- The buffer where data is stored.
count
protected int count
- The number of bytes in the buffer.
ByteArrayOutputStream
public ByteArrayOutputStream()
- Creates a new ByteArrayOutputStream.
ByteArrayOutputStream
public ByteArrayOutputStream(int size)
- Creates a new ByteArrayOutputStream with the specified initial size.
- Parameters:
- size - the initial size
write
public synchronized void write(int b)
- Writes a byte to the buffer.
- Parameters:
- b - the byte
- Overrides:
- write in class OutputStream
write
public synchronized void write(byte b[],
int off,
int len)
- Writes bytes to the buffer.
- Parameters:
- b - the data to be written
- off - the start offset in the data
- len - the number of bytes that are written
- Overrides:
- write in class OutputStream
writeTo
public synchronized void writeTo(OutputStream out) throws IOException
- Writes the contents of the buffer to another stream.
- Parameters:
- out - the output stream to write to
reset
public synchronized void reset()
- Resets the buffer so that you can use it again without
throwing away the already allocated buffer.
toByteArray
public synchronized byte[] toByteArray()
- Returns a copy of the input data.
size
public int size()
- Returns the current size of the buffer.
toString
public String toString()
- Converts input data to a string.
- Returns:
- the string.
- Overrides:
- toString in class Object
toString
public String toString(int hibyte)
- Converts input data to a string. The top 8 bits of each 16 bit Unicode character are set to hibyte.
- Parameters:
- hibyte - the bits set
All Packages Class Hierarchy This Package Previous Next Index