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()
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 java.io.InputStream |
toInputStream()
Gets the current contents of this byte stream as a 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)
Writes the bytes to the byte array.
|
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)
Write a byte to byte array.
|
abstract void |
writeTo(java.io.OutputStream out)
Writes the entire contents of this byte stream to the
specified output stream.
|
public abstract void write(byte[] b, int off, int len)
write
in class java.io.OutputStream
b
- the bytes to writeoff
- The start offsetlen
- The number of bytes to writepublic abstract void write(int b)
write
in class java.io.OutputStream
b
- the byte to writepublic 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 int size()
public void close() throws java.io.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 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 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)
public abstract java.io.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 java.lang.String toString()
toString(String)
insteadtoString
in class java.lang.Object
ByteArrayOutputStream.toString()
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 java.lang.String toString(java.nio.charset.Charset charset)
charset
- the character encodingByteArrayOutputStream.toString(String)
Copyright © 2010 - 2021 Adobe. All Rights Reserved