public class FastByteArrayOutputStream extends OutputStream
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
| Modifier and Type | Field and Description |
|---|---|
protected 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. |
static long |
ONEOVERPHI |
protected int |
position
The current writing position.
|
| Constructor and Description |
|---|
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.
|
| Modifier and Type | Method and Description |
|---|---|
static void |
ensureOffsetLength(int arrayLength,
int offset,
int length) |
static byte[] |
grow(byte[] array,
int length) |
static byte[] |
grow(byte[] array,
int length,
int preserve) |
long |
length() |
long |
position() |
void |
position(long newPosition) |
FastByteArrayOutputStream |
reset()
Marks this array output stream as empty.
|
int |
size() |
byte[] |
toByteArray() |
void |
write(byte[] b,
int off,
int len) |
void |
write(int b) |
close, flush, writepublic static final long ONEOVERPHI
public static final int DEFAULT_INITIAL_CAPACITY
public int length
array.protected byte[] array
protected int position
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.public static void ensureOffsetLength(int arrayLength,
int offset,
int length)
public static byte[] grow(byte[] array,
int length)
public static byte[] grow(byte[] array,
int length,
int preserve)
public FastByteArrayOutputStream reset()
public void write(int b)
write in class OutputStreampublic void write(byte[] b,
int off,
int len)
write in class OutputStreampublic void position(long newPosition)
public long position()
public long length()
throws IOException
IOExceptionpublic byte[] toByteArray()
public int size()
Copyright © 2018. All rights reserved.