Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

org.apache.axis.utils
Class ByteArrayOutputStream  view ByteArrayOutputStream download ByteArrayOutputStream.java

java.lang.Object
  extended byjava.io.OutputStream
      extended byorg.apache.axis.utils.ByteArrayOutputStream

public class ByteArrayOutputStream
extends java.io.OutputStream

This class implements an output stream in which the data is written into a byte array. The buffer automatically grows as data is written to it.

The data can be retrieved using toByteArray() and toString().

Closing a ByteArrayOutputStream has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.

This is an alternative implementation of the java.io.ByteArrayOutputStream class. The original implementation only allocates 32 bytes at the beginning. As this class is designed for heavy duty it starts at 1024 bytes. In contrast to the original it doesn't reallocate the whole memory block but allocates additional buffers. This way no buffers need to be garbage collected and the contents don't have to be copied to the new buffer. This class is designed to behave exactly like the original. The only exception is the deprecated toString(int) method that has been ignored.


Field Summary
private  java.util.List buffers
           
private  int count
           
private  byte[] currentBuffer
           
private  int currentBufferIndex
           
private  int filledBufferSum
           
 
Constructor Summary
ByteArrayOutputStream()
          Creates a new byte array output stream.
ByteArrayOutputStream(int size)
          Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes.
 
Method Summary
 void close()
          Closing a ByteArrayOutputStream has no effect.
private  byte[] getBuffer(int index)
           
private  void needNewBuffer(int newcount)
           
 void reset()
           
 int size()
           
 byte[] toByteArray()
           
 java.lang.String toString()
          Convert this Object to a human-readable String.
 java.lang.String toString(java.lang.String enc)
           
 void write(byte[] b, int off, int len)
          This method writes len bytes from the specified array b starting at index off into the array.
 void write(int b)
          Calls the write(byte[]) method.
 void writeTo(java.io.OutputStream out)
           
 
Methods inherited from class java.io.OutputStream
flush, write
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

buffers

private java.util.List buffers

currentBufferIndex

private int currentBufferIndex

filledBufferSum

private int filledBufferSum

currentBuffer

private byte[] currentBuffer

count

private int count
Constructor Detail

ByteArrayOutputStream

public ByteArrayOutputStream()
Creates a new byte array output stream. The buffer capacity is initially 1024 bytes, though its size increases if necessary.


ByteArrayOutputStream

public ByteArrayOutputStream(int size)
Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes.

Method Detail

getBuffer

private byte[] getBuffer(int index)

needNewBuffer

private void needNewBuffer(int newcount)

write

public void write(byte[] b,
                  int off,
                  int len)
Description copied from class: java.io.OutputStream
This method writes len bytes from the specified array b starting at index off into the array.

This method in this class calls the single byte write() method in a loop until all bytes have been written. Subclasses should override this method if possible in order to provide a more efficent implementation.


write

public void write(int b)
Calls the write(byte[]) method.


size

public int size()

close

public void close()
           throws java.io.IOException
Closing a ByteArrayOutputStream has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.


reset

public void reset()

writeTo

public void writeTo(java.io.OutputStream out)
             throws java.io.IOException

toByteArray

public byte[] toByteArray()

toString

public java.lang.String toString()
Description copied from class: java.lang.Object
Convert this Object to a human-readable String. There are no limits placed on how long this String should be or what it should contain. We suggest you make it as intuitive as possible to be able to place it into System.out.println() 55 and such.

It is typical, but not required, to ensure that this method never completes abruptly with a java.lang.RuntimeException.

This method will be called when performing string concatenation with this object. If the result is null, string concatenation will instead use "null".

The default implementation returns getClass().getName() + "@" + Integer.toHexString(hashCode()).


toString

public java.lang.String toString(java.lang.String enc)
                          throws java.io.UnsupportedEncodingException