|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
ObjectFastByteArrayWrapper
public class FastByteArrayWrapper
This class implements a byteArray wrapper to speed up working with byte
array. The buffer automatically grows as data is written to it. The data can
be retrieved using toByteArray()
and toString()
.
Closing a ByteArrayOutputStream has no effect. The methods in this class can be called after the stream has been closed without generating an IOException.
Field Summary | |
---|---|
protected byte[] |
buf
The buffer where data is stored. |
protected int |
count
The number of valid bytes in the buffer. |
Constructor Summary | |
---|---|
FastByteArrayWrapper()
Default constructor Creates a new byte array output stream. |
|
FastByteArrayWrapper(byte[] buffer)
Build a FastByteArrayWrapper with the inner buffer specified as
argument |
|
FastByteArrayWrapper(byte[] buffer,
int count)
Build a FastByteArrayWrapper with the inner buffer specified as
argument. |
|
FastByteArrayWrapper(int size)
Creates a new byte array output stream, with a buffer capacity of the specified size, in bytes. |
Method Summary | |
---|---|
byte[] |
getByteArray()
Creates a newly allocated byte array. |
void |
reset()
Resets the count field of this byte array wrapper to zero,
so that all currently accumulated values in the byte array is discarded. |
int |
size()
Returns the current size of the buffer. |
String |
toString()
Converts the buffer's contents into a string, translating bytes into characters according to the platform's default character encoding. |
void |
write(byte[] b)
Writes b.length bytes from the specified byte array
starting at offset 0 to this byte array wrapper. |
void |
write(byte[] b,
int off,
int len)
Writes len bytes from the specified byte array starting at
offset off to this byte array wrapper. |
void |
write(int b)
Writes the specified byte to this byte array wrapper. |
Methods inherited from class Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected byte[] buf
protected int count
Constructor Detail |
---|
public FastByteArrayWrapper()
public FastByteArrayWrapper(byte[] buffer)
FastByteArrayWrapper
with the inner buffer specified as
argument
buffer
- the inner buffer used by this FastByteArrayWrapper
public FastByteArrayWrapper(byte[] buffer, int count)
FastByteArrayWrapper
with the inner buffer specified as
argument.
buffer
- the inner buffer used by this FastByteArrayWrapper
count
- the number of valid bytes in the provided bufferpublic FastByteArrayWrapper(int size)
size
- the initial size.
IllegalArgumentException
- if size is negative.Method Detail |
---|
public void write(int b)
b
- the byte to be written.public void write(byte[] b, int off, int len)
len
bytes from the specified byte array starting at
offset off
to this byte array wrapper.
b
- the data.off
- the start offset in the data.len
- the number of bytes to write.public void write(byte[] b) throws IOException
b.length
bytes from the specified byte array
starting at offset 0 to this byte array wrapper.
b
- the data.
IOException
public void reset()
count
field of this byte array wrapper to zero,
so that all currently accumulated values in the byte array is discarded.
public byte[] getByteArray()
ByteArrayOutputStream.size()
public int size()
count
field, which is the number
of valid bytes in the buffer.ByteArrayOutputStream.count
public String toString()
toString
in class Object
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |