Name
ByteArrayOutputStream
Synopsis
This subclass of OutputStream
stores data written to it
in a buffer which can later be retrieved using its
toByteArray()
method. When the stream is created, the
buffer is empty. It is then expanded as data is written to the stream.
ByteArrayOutputStream
is often used in J2ME in
conjunction with a DataOutputStream
to allow strings and
Java primitives types to be stored in a byte array. This byte array is
written to persistent storage on a device using the
RecordStore
APIs in the
javax.microedition.rms
package.
public class ByteArrayOutputStream extends OutputStream { // Public Constructors public ByteArrayOutputStream(); public ByteArrayOutputStream( int size); // Public Instance Methods public void reset(); // synchronized public int size(); public byte[] toByteArray(); // synchronized // Public Methods Overriding OutputStream public void close() throws IOException; // synchronized public void write( int b); // synchronized public void write( byte[] b, int off, int len); // synchronized // Public Methods Overriding Object public String toString(); // Protected Instance Fields protected byte[] buf; protected int count; }
Get J2ME in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.