|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.OutputStream
it.unimi.dsi.fastutil.io.MeasurableOutputStream
it.unimi.dsi.fastutil.io.FastByteArrayOutputStream
public class FastByteArrayOutputStream
Simple, fast byte-array output stream that exposes the backing array.
ByteArrayOutputStream
is nice, but to get its content you
must generate each time a new object. This doesn't happen here.
This class will automatically enlarge the backing array, doubling its
size whenever new space is needed. The reset()
method will
mark the content as empty, but will not decrease the capacity: use
trim()
for that purpose.
Field Summary | |
---|---|
byte[] |
array
The array backing the output stream. |
static int |
DEFAULT_INITIAL_CAPACITY
The array backing the output stream. |
int |
length
The number of valid bytes in array . |
Constructor Summary | |
---|---|
FastByteArrayOutputStream()
Creates a new array output stream with an initial capacity of DEFAULT_INITIAL_CAPACITY bytes. |
|
FastByteArrayOutputStream(byte[] a)
Creates a new array output stream wrapping a given byte array. |
|
FastByteArrayOutputStream(int initialCapacity)
Creates a new array output stream with a given initial capacity. |
Method Summary | |
---|---|
long |
length()
Returns the overall length of this stream (optional operation). |
long |
position()
Returns the current stream position. |
void |
position(long newPosition)
Sets the current stream position. |
void |
reset()
Marks this array output stream as empty. |
void |
trim()
Ensures that the length of the backing array is equal to length . |
void |
write(byte[] b,
int off,
int len)
|
void |
write(int b)
|
Methods inherited from class java.io.OutputStream |
---|
close, flush, write |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int DEFAULT_INITIAL_CAPACITY
public byte[] array
public int length
array
.
Constructor Detail |
---|
public FastByteArrayOutputStream()
DEFAULT_INITIAL_CAPACITY
bytes.
public FastByteArrayOutputStream(int initialCapacity)
initialCapacity
- the initial length of the backing array.public FastByteArrayOutputStream(byte[] a)
a
- the byte array to wrap.Method Detail |
---|
public void reset()
public void trim()
length
.
public void write(int b)
write
in class OutputStream
public void write(byte[] b, int off, int len) throws IOException
write
in class OutputStream
IOException
public void position(long newPosition)
RepositionableStream
position
in interface RepositionableStream
newPosition
- the new stream position.public long position()
RepositionableStream
position
in interface MeasurableStream
position
in interface RepositionableStream
public long length() throws IOException
MeasurableStream
length
in interface MeasurableStream
IOException
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |