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().

Variable Index

 o buf
The buffer where data is stored.
 o count
The number of bytes in the buffer.

Constructor Index

 o ByteArrayOutputStream()
Creates a new ByteArrayOutputStream.
 o ByteArrayOutputStream(int)
Creates a new ByteArrayOutputStream with the specified initial size.

Method Index

 o reset()
Resets the buffer so that you can use it again without throwing away the already allocated buffer.
 o size()
Returns the current size of the buffer.
 o toByteArray()
Returns a copy of the input data.
 o toString()
Converts input data to a string.
 o toString(int)
Converts input data to a string.
 o write(byte[], int, int)
Writes bytes to the buffer.
 o write(int)
Writes a byte to the buffer.
 o writeTo(OutputStream)
Writes the contents of the buffer to another stream.

Variables

 o buf
  protected byte buf[]
The buffer where data is stored.
 o count
  protected int count
The number of bytes in the buffer.

Constructors

 o ByteArrayOutputStream
  public ByteArrayOutputStream()
Creates a new ByteArrayOutputStream.
 o ByteArrayOutputStream
  public ByteArrayOutputStream(int size)
Creates a new ByteArrayOutputStream with the specified initial size.
Parameters:
size - the initial size

Methods

 o write
  public synchronized void write(int b)
Writes a byte to the buffer.
Parameters:
b - the byte
Overrides:
write in class OutputStream
 o 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
 o 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
 o reset
  public synchronized void reset()
Resets the buffer so that you can use it again without throwing away the already allocated buffer.
 o toByteArray
  public synchronized byte[] toByteArray()
Returns a copy of the input data.
 o size
  public int size()
Returns the current size of the buffer.
 o toString
  public String toString()
Converts input data to a string.
Returns:
the string.
Overrides:
toString in class Object
 o 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