DthingApi
Public Member Functions | Protected Attributes | List of all members
java.io.ByteArrayOutputStream Class Reference
Inheritance diagram for java.io.ByteArrayOutputStream:
java.io.OutputStream

Public Member Functions

 ByteArrayOutputStream ()
 
 ByteArrayOutputStream (int size)
 
void close () throws IOException
 
synchronized void reset ()
 
int size ()
 
synchronized byte [] toByteArray ()
 
String toString ()
 
String toString (String enc) throws UnsupportedEncodingException
 
synchronized void write (byte[] buffer, int offset, int len)
 
synchronized void write (int oneByte)
 
synchronized void writeTo (OutputStream out) throws IOException
 
- Public Member Functions inherited from java.io.OutputStream
 OutputStream ()
 
void close () throws IOException
 
void flush () throws IOException
 
void write (byte[] buffer) throws IOException
 
void write (byte[] buffer, int offset, int count) throws IOException
 
abstract void write (int oneByte) throws IOException
 

Protected Attributes

byte [] buf
 
int count
 

Detailed Description

A specialized OutputStream for class for writing content to an (internal) byte array. As bytes are written to this stream, the byte array may be expanded to hold more bytes. When the writing is considered to be finished, a copy of the byte array can be requested from the class.

See also
ByteArrayInputStream

Constructor & Destructor Documentation

◆ ByteArrayOutputStream() [1/2]

java.io.ByteArrayOutputStream.ByteArrayOutputStream ( )
inline

Constructs a new ByteArrayOutputStream with a default size of 32 bytes. If more than 32 bytes are written to this instance, the underlying byte array will expand.

◆ ByteArrayOutputStream() [2/2]

java.io.ByteArrayOutputStream.ByteArrayOutputStream ( int  size)
inline

Constructs a new

with a default size of

bytes. If more than

bytes are written to this instance, the underlying byte array will expand.

Parameters
sizeinitial size for the underlying byte array, must be non-negative.
Exceptions
IllegalArgumentExceptionif < 0.

Member Function Documentation

◆ close()

void java.io.ByteArrayOutputStream.close ( ) throws IOException
inline

Closes this stream. This releases system resources used for this stream.

Exceptions
IOExceptionif an error occurs while attempting to close this stream.

Although the spec claims "A closed stream cannot perform output operations and cannot be reopened.", this implementation must do nothing.

◆ reset()

synchronized void java.io.ByteArrayOutputStream.reset ( )
inline

Resets this stream to the beginning of the underlying byte array. All subsequent writes will overwrite any bytes previously stored in this stream.

◆ size()

int java.io.ByteArrayOutputStream.size ( )
inline

Returns the total number of bytes written to this stream so far.

Returns
the number of bytes written to this stream.

◆ toByteArray()

synchronized byte [] java.io.ByteArrayOutputStream.toByteArray ( )
inline

Returns the contents of this ByteArrayOutputStream as a byte array. Any changes made to the receiver after returning will not be reflected in the byte array returned to the caller.

Returns
this stream's current contents as a byte array.

◆ toString() [1/2]

String java.io.ByteArrayOutputStream.toString ( )
inline

Returns the contents of this ByteArrayOutputStream as a string. Any changes made to the receiver after returning will not be reflected in the string returned to the caller.

Returns
this stream's current contents as a string.

◆ toString() [2/2]

String java.io.ByteArrayOutputStream.toString ( String  enc) throws UnsupportedEncodingException
inline

Returns the contents of this ByteArrayOutputStream as a string converted according to the encoding declared in

enc

.

Parameters
enca string representing the encoding to use when translating this stream to a string.
Returns
this stream's current contents as an encoded string.
Exceptions
UnsupportedEncodingExceptionif the provided encoding is not supported.

◆ write() [1/2]

synchronized void java.io.ByteArrayOutputStream.write ( byte []  buffer,
int  offset,
int  len 
)
inline

Writes

bytes from the byte array

buffer

starting at offset

index

to this stream.

Parameters
bufferthe buffer to be written.
offsetthe initial position in
buffer
to retrieve bytes.
lenthe number of bytes of
buffer
to write.
Exceptions
NullPointerExceptionif
buffer
is
null
.
IndexOutOfBoundsExceptionif
offset < 0
or
len < 0
, or if
offset + len
is greater than the length of
buffer
.

◆ write() [2/2]

synchronized void java.io.ByteArrayOutputStream.write ( int  oneByte)
inline

Writes the specified byte

oneByte

to the OutputStream. Only the low order byte of

oneByte

is written.

Parameters
oneBytethe byte to be written.

◆ writeTo()

synchronized void java.io.ByteArrayOutputStream.writeTo ( OutputStream  out) throws IOException
inline

Takes the contents of this stream and writes it to the output stream

out

.

Parameters
outan OutputStream on which to write the contents of this stream.
Exceptions
IOExceptionif an error occurs while writing to
out
.

Member Data Documentation

◆ buf

byte [] java.io.ByteArrayOutputStream.buf
protected

The byte array containing the bytes written.

◆ count

int java.io.ByteArrayOutputStream.count
protected

The number of bytes written.


The documentation for this class was generated from the following file: