public abstract class AbstractByteArrayOutputStream
extends java.io.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()
Does nothing.
|
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 java.io.InputStream |
toInputStream()
Gets the current contents of this byte stream as an Input Stream.
|
java.lang.String |
toString()
Deprecated.
2.5 use
toString(String) instead |
java.lang.String |
toString(java.nio.charset.Charset charset)
Gets the current contents of this byte stream as a string
using the specified encoding.
|
java.lang.String |
toString(java.lang.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) |
abstract int |
write(java.io.InputStream in)
Writes the entire contents of the specified input stream to this
byte stream.
|
abstract void |
write(int b) |
abstract void |
writeTo(java.io.OutputStream out)
Writes the entire contents of this byte stream to the
specified output stream.
|
public void close() throws java.io.IOException
IOException
.close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.OutputStream
java.io.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 int size()
public abstract byte[] toByteArray()
ByteArrayOutputStream.toByteArray()
public abstract java.io.InputStream toInputStream()
this
stream,
avoiding memory allocation and copy, thus saving space and time.ByteArrayOutputStream.toByteArray()
,
reset()
@Deprecated public java.lang.String toString()
toString(String)
insteadtoString
in class java.lang.Object
ByteArrayOutputStream.toString()
public java.lang.String toString(java.nio.charset.Charset charset)
charset
- the character encodingByteArrayOutputStream.toString(String)
public java.lang.String toString(java.lang.String enc) throws java.io.UnsupportedEncodingException
enc
- the name of the character encodingjava.io.UnsupportedEncodingException
- if the encoding is not supportedByteArrayOutputStream.toString(String)
public abstract void write(byte[] b, int off, int len)
write
in class java.io.OutputStream
public abstract int write(java.io.InputStream in) throws java.io.IOException
in
- the input stream to read fromjava.io.IOException
- if an I/O error occurs while reading the input streampublic abstract void write(int b)
write
in class java.io.OutputStream
public abstract void writeTo(java.io.OutputStream out) throws java.io.IOException
out
- the output stream to write tojava.io.IOException
- if an I/O error occurs, such as if the stream is closedByteArrayOutputStream.writeTo(OutputStream)
Copyright © 2010 - 2023 Adobe. All Rights Reserved