| java.lang.Object java.io.OutputStream org.apache.commons.io.output.ByteArrayOutputStream
ByteArrayOutputStream | public class ByteArrayOutputStream extends OutputStream (Code) | | 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.
author: Jeremias Maerki author: Holger Hoffstatte version: $Id: ByteArrayOutputStream.java 491007 2006-12-29 13:50:34Z scolebourne $ |
Constructor Summary | |
public | ByteArrayOutputStream() Creates a new byte array output stream. | public | ByteArrayOutputStream(int size) Creates a new byte array output stream, with a buffer capacity of
the specified size, in bytes. |
Method Summary | |
public void | close() Closing a ByteArrayOutputStream has no effect. | public synchronized void | reset() | public synchronized int | size() | public synchronized byte[] | toByteArray() Gets the curent contents of this byte stream as a byte array. | public String | toString() Gets the curent contents of this byte stream as a string. | public String | toString(String enc) Gets the curent contents of this byte stream as a string
using the specified encoding. | public void | write(byte[] b, int off, int len) | public synchronized void | write(int b) | public synchronized void | writeTo(OutputStream out) Writes the entire contents of this byte stream to the
specified output stream. |
ByteArrayOutputStream | public ByteArrayOutputStream()(Code) | | 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)(Code) | | Creates a new byte array output stream, with a buffer capacity of
the specified size, in bytes.
Parameters: size - the initial size throws: IllegalArgumentException - if size is negative |
close | public void close() throws IOException(Code) | | Closing a ByteArrayOutputStream has no effect. The methods in
this class can be called after the stream has been closed without
generating an IOException.
throws: IOException - never (this method should not declare this exceptionbut it has to now due to backwards compatability) |
toByteArray | public synchronized byte[] toByteArray()(Code) | | Gets the curent contents of this byte stream as a byte array.
The result is independent of this stream.
the current contents of this output stream, as a byte array See Also: java.io.ByteArrayOutputStream.toByteArray |
|
|