public class ByteArrayOutputStream extends AbstractByteArrayOutputStream
AbstractByteArrayOutputStream
using instance synchronization.Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
void |
reset() |
int |
size()
Returns the current size of the byte array.
|
static InputStream |
toBufferedInputStream(InputStream input)
Fetches entire contents of an
InputStream and represent
same data as result InputStream. |
static InputStream |
toBufferedInputStream(InputStream input,
int size)
Fetches entire contents of an
InputStream and represent
same data as result InputStream. |
byte[] |
toByteArray()
Gets the current contents of this byte stream as a byte array.
|
InputStream |
toInputStream()
Gets the current contents of this byte stream as a Input Stream.
|
void |
write(byte[] b,
int off,
int len)
Writes the bytes to the byte array.
|
int |
write(InputStream in)
Writes the entire contents of the specified input stream to this
byte stream.
|
void |
write(int b)
Write a byte to byte array.
|
void |
writeTo(OutputStream out)
Writes the entire contents of this byte stream to the
specified output stream.
|
close, toString, toString, toString
flush, write
public ByteArrayOutputStream()
public ByteArrayOutputStream(int size)
size
- the initial sizeIllegalArgumentException
- if size is negativepublic void write(byte[] b, int off, int len)
AbstractByteArrayOutputStream
write
in class AbstractByteArrayOutputStream
b
- the bytes to writeoff
- The start offsetlen
- The number of bytes to writepublic void write(int b)
AbstractByteArrayOutputStream
write
in class AbstractByteArrayOutputStream
b
- the byte to writepublic int write(InputStream in) throws IOException
AbstractByteArrayOutputStream
write
in class AbstractByteArrayOutputStream
in
- the input stream to read fromIOException
- if an I/O error occurs while reading the input streampublic int size()
AbstractByteArrayOutputStream
size
in class AbstractByteArrayOutputStream
public void reset()
reset
in class AbstractByteArrayOutputStream
ByteArrayOutputStream.reset()
public void writeTo(OutputStream out) throws IOException
AbstractByteArrayOutputStream
writeTo
in class AbstractByteArrayOutputStream
out
- the output stream to write toIOException
- if an I/O error occurs, such as if the stream is closedByteArrayOutputStream.writeTo(OutputStream)
public static InputStream toBufferedInputStream(InputStream input) throws IOException
InputStream
and represent
same data as result InputStream.
This method is useful where,
toByteArray()
, since it
avoids unnecessary allocation and copy of byte[].BufferedInputStream
.input
- Stream to be fully buffered.IOException
- if an I/O error occurspublic static InputStream toBufferedInputStream(InputStream input, int size) throws IOException
InputStream
and represent
same data as result InputStream.
This method is useful where,
toByteArray()
, since it
avoids unnecessary allocation and copy of byte[].BufferedInputStream
.input
- Stream to be fully buffered.size
- the initial buffer sizeIOException
- if an I/O error occurspublic InputStream toInputStream()
AbstractByteArrayOutputStream
this
stream,
avoiding memory allocation and copy, thus saving space and time.toInputStream
in class AbstractByteArrayOutputStream
ByteArrayOutputStream.toByteArray()
,
AbstractByteArrayOutputStream.reset()
public byte[] toByteArray()
AbstractByteArrayOutputStream
toByteArray
in class AbstractByteArrayOutputStream
ByteArrayOutputStream.toByteArray()
Jas4pp 1.5 © Java Analysis Studio for Particle Physics