    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, using the platform's default character encoding.
toString(int)
  Converts input data to a string. Deprecated.
toString(String)
  Converts input data to a string, using the specified character encoding.
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, using the platform's default character encoding.

  Overrides:
    toString in class Object

toString

      public String toString(String enc) throws UnsupportedEncodingException

  Converts input data to a string, using the specified character encoding.

  Parameters:
    enc - A character-encoding name

toString

      public String toString(int hibyte)

  Note: toString() is deprecated. This method does not properly convert bytes into characters. As of JDK version 1.1, the preferred way to do this is via the toString method that takes an encoding-name argument, or that uses the platform's default character encoding.

  Converts input data to a string. The top 8 bits of each 16 bit Unicode character are set to hibyte.

  Parameters:
    hibyte - The high byte of each resulting Unicode character.

    All Packages  Class Hierarchy  This Package  Previous  Next  Index