THE Java™ Programming Language, Fourth Edition

(Jeff_L) #1
Creates a ByteArrayInputStream from the specified array of bytes
using only the part of buf from buf[offset] to
buf[offset+count-1] or the end of the array, whichever is smaller.
The input array is used directly, not copied, so you should take care not to
modify it while it is being used as an input source.

publicByteArrayInputStream(byte[] buf)

Equivalent to ByteArrayInputStream(buf,0,buf.length).

The ByteArrayOutputStream class provides a dynamically growing byte array to hold output. It adds
constructors and methods:


publicByteArrayOutputStream()

Creates a new ByteArrayOutputStream with a default initial array size.

publicByteArrayOutputStream(int size)

Creates a new ByteArrayOutputStream with the given initial array
size.

public intsize()

Returns the number of bytes generated thus far by output to the stream.

public byte[]toByteArray()

Returns a copy of the bytes generated thus far by output to the stream. When
you are finished writing into a ByteArrayOutputStream via upstream
filter streams, you should flush the upstream objects before using
toByteArray.

public voidreset()

Resets the stream to reuse the current buffer, discarding its contents.

public StringtoString()

Returns the current contents of the buffer as a String, translating bytes into
characters according to the default character encoding.

public StringtoString(String enc)tHRows
UnsupportedEncodingException

Returns the current contents of the buffer as a String, translating bytes into
characters according to the specified character encoding. If the encoding is
not supported an UnsupportedEncodingException is thrown.

public voidwriteTo(OutputStream out)throws IOException

Writes the current contents of the buffer to the stream out.
Free download pdf