? AbstractByteArrayOutputStream
- ????????:
Closeable
,Flushable
,AutoCloseable
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 1024 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.
- ???????:
- 2.7
-
?????
????????????protected static interface
Constructor for an InputStream subclass. -
????
?? -
?????
??? -
????
??????????void
close()
Closing aByteArrayOutputStream
has no effect.protected void
needNewBuffer
(int newcount) Makes a new buffer available either by allocating a new one or re-cycling an existing one.abstract void
reset()
protected void
abstract int
size()
Returns the current size of the byte array.abstract byte[]
Gets the current contents of this byte stream as a byte array.protected byte[]
Gets the current contents of this byte stream as a byte array.abstract InputStream
Gets the current contents of this byte stream as a Input Stream.protected <T extends InputStream>
InputStreamtoInputStream
(AbstractByteArrayOutputStream.InputStreamConstructor<T> isConstructor) Gets the current contents of this byte stream as a Input Stream.toString()
????Gets the current contents of this byte stream as a string using the specified encoding.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 void
write
(int b) Write a byte to byte array.abstract int
write
(InputStream in) Writes the entire contents of the specified input stream to this byte stream.protected void
writeImpl
(byte[] b, int off, int len) Writes the bytes to the byte array.protected void
writeImpl
(int b) Write a byte to byte array.protected int
writeImpl
(InputStream in) Writes the entire contents of the specified input stream to this byte stream.abstract void
writeTo
(OutputStream out) Writes the entire contents of this byte stream to the specified output stream.protected void
writeToImpl
(OutputStream out) Writes the entire contents of this byte stream to the specified output stream.??????? java.io.OutputStream
flush, nullOutputStream, write
-
??????
-
count
The total count of bytes written.
-
-
???????
-
AbstractByteArrayOutputStream
public AbstractByteArrayOutputStream()
-
-
??????
-
needNewBuffer
Makes a new buffer available either by allocating a new one or re-cycling an existing one.- ??:
newcount
- the size of the buffer if one is created
-
write
Writes the bytes to the byte array.- ??:
write
???OutputStream
- ??:
b
- the bytes to writeoff
- The start offsetlen
- The number of bytes to write
-
writeImpl
Writes the bytes to the byte array.- ??:
b
- the bytes to writeoff
- The start offsetlen
- The number of bytes to write
-
write
Write a byte to byte array.- ???:
write
???OutputStream
- ??:
b
- the byte to write
-
writeImpl
Write a byte to byte array.- ??:
b
- the byte to write
-
write
Writes the entire contents of the specified input stream to this byte stream. Bytes from the input stream are read directly into the internal buffers of this streams.- ??:
in
- the input stream to read from- ??:
- total number of bytes read from the input stream (and written to this stream)
- ??:
IOException
- if an I/O error occurs while reading the input stream- ???????:
- 1.4
-
writeImpl
Writes the entire contents of the specified input stream to this byte stream. Bytes from the input stream are read directly into the internal buffers of this streams.- ??:
in
- the input stream to read from- ??:
- total number of bytes read from the input stream (and written to this stream)
- ??:
IOException
- if an I/O error occurs while reading the input stream- ???????:
- 2.7
-
size
Returns the current size of the byte array.- ??:
- the current size of the byte array
-
close
Closing aByteArrayOutputStream
has no effect. The methods in this class can be called after the stream has been closed without generating anIOException
.- ???:
close
????AutoCloseable
- ???:
close
????Closeable
- ??:
close
???OutputStream
- ??:
IOException
- never (this method should not declare this exception but it has to now due to backwards compatibility)
-
reset
-
resetImpl
-
writeTo
Writes the entire contents of this byte stream to the specified output stream.- ??:
out
- the output stream to write to- ??:
IOException
- if an I/O error occurs, such as if the stream is closed- ????:
-
writeToImpl
Writes the entire contents of this byte stream to the specified output stream.- ??:
out
- the output stream to write to- ??:
IOException
- if an I/O error occurs, such as if the stream is closed- ????:
-
toInputStream
Gets the current contents of this byte stream as a Input Stream. The returned stream is backed by buffers ofthis
stream, avoiding memory allocation and copy, thus saving space and time.- ??:
- the current contents of this output stream.
- ???????:
- 2.5
- ????:
-
toInputStream
protected <T extends InputStream> InputStream toInputStream(AbstractByteArrayOutputStream.InputStreamConstructor<T> isConstructor) Gets the current contents of this byte stream as a Input Stream. The returned stream is backed by buffers ofthis
stream, avoiding memory allocation and copy, thus saving space and time.- ????:
T
- the type of the InputStream which makes up theSequenceInputStream
.- ??:
isConstructor
- A constructor for an InputStream which makes up theSequenceInputStream
.- ??:
- the current contents of this output stream.
- ???????:
- 2.7
- ????:
-
toByteArray
Gets the current contents of this byte stream as a byte array. The result is independent of this stream.- ??:
- the current contents of this output stream, as a byte array
- ????:
-
toByteArrayImpl
Gets the current contents of this byte stream as a byte array. The result is independent of this stream.- ??:
- the current contents of this output stream, as a byte array
- ????:
-
toString
????2.5 usetoString(String)
insteadGets the current contents of this byte stream as a string using the platform default charset. -
toString
Gets the current contents of this byte stream as a string using the specified encoding.- ??:
enc
- the name of the character encoding- ??:
- the string converted from the byte array
- ??:
UnsupportedEncodingException
- if the encoding is not supported- ????:
-
toString
Gets the current contents of this byte stream as a string using the specified encoding.- ??:
charset
- the character encoding- ??:
- the string converted from the byte array
- ???????:
- 2.5
- ????:
-
toString(String)
instead