public class FastByteArrayOutputStream
extends java.io.OutputStream
OutputStream
for class for writing content to an
(internal) byte array. As bytes are written to this stream, the byte array
may be expanded to hold more bytes. When the writing is considered to be
finished, a copy of the byte array can be requested from the class.ByteArrayOutputStream
Modifier and Type | Field and Description |
---|---|
protected byte[] |
buf
The byte array containing the bytes written.
|
protected int |
count
The number of bytes written.
|
Constructor and Description |
---|
FastByteArrayOutputStream()
Constructs a new ByteArrayOutputStream with a default size of 32 bytes.
|
FastByteArrayOutputStream(int size)
Constructs a new
ByteArrayOutputStream with a default size of
size bytes. |
Modifier and Type | Method and Description |
---|---|
void |
close()
Closes this stream.
|
void |
reset()
Resets this stream to the beginning of the underlying byte array.
|
int |
size()
Returns the total number of bytes written to this stream so far.
|
byte[] |
toByteArray()
Returns the contents of this ByteArrayOutputStream as a byte array.
|
java.lang.String |
toString()
Returns the contents of this ByteArrayOutputStream as a string.
|
java.lang.String |
toString(int hibyte)
Deprecated.
Use
toString() . |
java.lang.String |
toString(java.lang.String enc)
Returns the contents of this ByteArrayOutputStream as a string converted
according to the encoding declared in
enc . |
void |
write(byte[] buffer,
int offset,
int len)
Writes
count bytes from the byte array buffer starting at
offset index to this stream. |
void |
write(int oneByte)
Writes the specified byte
oneByte to the OutputStream. |
void |
writeTo(java.io.OutputStream out)
Takes the contents of this stream and writes it to the output stream
out . |
protected byte[] buf
protected int count
public FastByteArrayOutputStream()
public FastByteArrayOutputStream(int size)
ByteArrayOutputStream
with a default size of
size
bytes. If more than size
bytes are written to this
instance, the underlying byte array will expand.size
- initial size for the underlying byte array, must be
non-negative.java.lang.IllegalArgumentException
- if size
< 0.public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.OutputStream
java.io.IOException
- if an error occurs while attempting to close this stream.public void reset()
public int size()
public byte[] toByteArray()
public java.lang.String toString()
toString
in class java.lang.Object
@Deprecated public java.lang.String toString(int hibyte)
toString()
.b
in this stream is converted to a character c
using the
following function:
c == (char)(((hibyte & 0xff) << 8) | (b & 0xff))
. This method is
deprecated and either toString()
or toString(String)
should be used.hibyte
- the high byte of each resulting Unicode character.hibyte
.public java.lang.String toString(java.lang.String enc) throws java.io.UnsupportedEncodingException
enc
.enc
- a string representing the encoding to use when translating
this stream to a string.java.io.UnsupportedEncodingException
- if the provided encoding is not supported.public void write(byte[] buffer, int offset, int len)
count
bytes from the byte array buffer
starting at
offset index
to this stream.write
in class java.io.OutputStream
buffer
- the buffer to be written.offset
- the initial position in buffer
to retrieve bytes.len
- the number of bytes of buffer
to write.java.lang.NullPointerException
- if buffer
is null
.java.lang.IndexOutOfBoundsException
- if offset < 0
or len < 0
, or if
offset + len
is greater than the length of
buffer
.public void write(int oneByte)
oneByte
to the OutputStream. Only the
low order byte of oneByte
is written.write
in class java.io.OutputStream
oneByte
- the byte to be written.public void writeTo(java.io.OutputStream out) throws java.io.IOException
out
.out
- an OutputStream on which to write the contents of this stream.java.io.IOException
- if an error occurs while writing to out
.Copyright © 2021. All Rights Reserved.