|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.io.OutputStream org.apache.lucene.util.UnsafeByteArrayOutputStream
public class UnsafeByteArrayOutputStream
This class is used as a wrapper to a byte array, extending
OutputStream
. Data is written in the given byte[] buffer, until its
length is insufficient. Than the buffer size is doubled and the data is
written.
This class is Unsafe as it is using a buffer which potentially can be changed
from the outside. Moreover, when toByteArray()
is called, the buffer
itself is returned, and not a copy.
Constructor Summary | |
---|---|
UnsafeByteArrayOutputStream()
Constructs a new output stream, with a default allocated buffer which can later be obtained via toByteArray() . |
|
UnsafeByteArrayOutputStream(byte[] buffer)
Constructs a new output stream, with a given buffer. |
|
UnsafeByteArrayOutputStream(byte[] buffer,
int startPos)
Constructs a new output stream, with a given buffer. |
Method Summary | |
---|---|
int |
getStartPos()
Returns the start position data was written to. |
int |
length()
Returns the number of relevant bytes. |
void |
reInit(byte[] buffer)
For reuse-ability, this stream object can be re-initialized with another given buffer, using 0 as default starting position. |
void |
reInit(byte[] buffer,
int startPos)
For reuse-ability, this stream object can be re-initialized with another given buffer and starting position. |
byte[] |
toByteArray()
Returns the byte array saved within the buffer AS IS. |
void |
write(byte[] b,
int off,
int len)
writes a given byte[], with offset and length to the buffer. |
void |
write(int value)
writes a given byte(at the form of an int) to the buffer. |
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 |
Constructor Detail |
---|
public UnsafeByteArrayOutputStream()
toByteArray()
.
public UnsafeByteArrayOutputStream(byte[] buffer)
buffer
- some space to which writing will be madepublic UnsafeByteArrayOutputStream(byte[] buffer, int startPos)
buffer
- some space to which writing will be made.startPos
- an index (inclusive) from white data will be written.Method Detail |
---|
public void reInit(byte[] buffer, int startPos)
buffer
- some space to which writing will be made.startPos
- an index (inclusive) from white data will be written.public void reInit(byte[] buffer)
buffer
- some space to which writing will be made.public void write(int value) throws IOException
write
in class OutputStream
value
- byte value to be written
IOException
public void write(byte[] b, int off, int len) throws IOException
write
in class OutputStream
b
- byte buffer, containing the source data to be writtenoff
- index from which data from the buffer b should be writtenlen
- number of bytes that should be written
IOException
public byte[] toByteArray()
public int length()
public int getStartPos()
reInit(byte[], int)
or
UnsafeByteArrayOutputStream(byte[], int)
and passed a start
position which is not 0.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |