public abstract class AbstractByteArrayOutputStream extends OutputStream
The data can be retrieved using toByteArray()
and
toString()
.
Closing an AbstractByteArrayOutputStream
has no effect. The methods in
this class can be called after the stream has been closed without
generating an IOException
.
This is the base for an alternative implementation of the
ByteArrayOutputStream
class. The original implementation
only allocates 32 bytes at the beginning. As this class is designed for
heavy duty it starts at 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
ByteArrayOutputStream.toString(int)
method that has been
ignored.
Constructor and Description |
---|
AbstractByteArrayOutputStream() |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closing a
ByteArrayOutputStream has no effect. |
abstract void |
reset() |
abstract int |
size()
Returns the current size of the byte array.
|
abstract byte[] |
toByteArray()
Gets the current contents of this byte stream as a byte array.
|
abstract InputStream |
toInputStream()
Gets the current contents of this byte stream as a Input Stream.
|
String |
toString()
Deprecated.
2.5 use
toString(String) instead |
String |
toString(Charset charset)
Gets the current contents of this byte stream as a string
using the specified encoding.
|
String |
toString(String enc)
Gets the current contents of this byte stream as a string
using the specified encoding.
|
abstract void |
write(byte[] b,
int off,
int len)
Writes the bytes to the byte array.
|
abstract int |
write(InputStream in)
Writes the entire contents of the specified input stream to this
byte stream.
|
abstract void |
write(int b)
Write a byte to byte array.
|
abstract void |
writeTo(OutputStream out)
Writes the entire contents of this byte stream to the
specified output stream.
|
flush, write
public abstract void write(byte[] b, int off, int len)
write
in class OutputStream
b
- the bytes to writeoff
- The start offsetlen
- The number of bytes to writepublic abstract void write(int b)
write
in class OutputStream
b
- the byte to writepublic abstract int write(InputStream in) throws IOException
in
- the input stream to read fromIOException
- if an I/O error occurs while reading the input streampublic abstract int size()
public void close() throws IOException
ByteArrayOutputStream
has no effect. The methods in
this class can be called after the stream has been closed without
generating an IOException
.close
in interface Closeable
close
in interface AutoCloseable
close
in class OutputStream
IOException
- never (this method should not declare this exception
but it has to now due to backwards compatibility)public abstract void reset()
ByteArrayOutputStream.reset()
public abstract void writeTo(OutputStream out) throws IOException
out
- the output stream to write toIOException
- if an I/O error occurs, such as if the stream is closedByteArrayOutputStream.writeTo(OutputStream)
public abstract InputStream toInputStream()
this
stream,
avoiding memory allocation and copy, thus saving space and time.ByteArrayOutputStream.toByteArray()
,
reset()
public abstract byte[] toByteArray()
ByteArrayOutputStream.toByteArray()
@Deprecated public String toString()
toString(String)
insteadtoString
in class Object
ByteArrayOutputStream.toString()
public String toString(String enc) throws UnsupportedEncodingException
enc
- the name of the character encodingUnsupportedEncodingException
- if the encoding is not supportedByteArrayOutputStream.toString(String)
public String toString(Charset charset)
charset
- the character encodingByteArrayOutputStream.toString(String)
Jas4pp 1.5 © Java Analysis Studio for Particle Physics