public class ByteOutputBuffer extends Object
Once an array has been written to an output stream or to a byte array, the object can be reused as a new stream if the reset() method is called.
Unlike the ByteArrayOutputStream class, this class is not thread safe.
reset()
Modifier and Type | Field and Description |
---|---|
static int |
BUF_DEF_LEN
The default initial buffer size
|
static int |
BUF_INC
The buffer increase size
|
Constructor and Description |
---|
ByteOutputBuffer()
Creates a new byte array output stream.
|
ByteOutputBuffer(int size)
Creates a new byte array output stream, with a buffer capacity
of the specified size, in bytes.
|
Modifier and Type | Method and Description |
---|---|
int |
getByte(int pos)
Returns the byte buffered at the given position in the buffer.
|
void |
reset()
Discards all the buffered data, by resetting the counter of written
bytes to 0.
|
int |
size()
Returns the number of valid bytes in the output buffer (count class
variable).
|
void |
toByteArray(int off,
int len,
byte[] outbuf,
int outoff)
Copies the specified part of the stream to the 'outbuf' byte
array.
|
void |
write(int b)
Writes the specified byte to this byte array output stream.
|
public static final int BUF_INC
public static final int BUF_DEF_LEN
public ByteOutputBuffer()
public ByteOutputBuffer(int size)
size
- the initial size.public final void write(int b)
b
- The byte to writepublic void toByteArray(int off, int len, byte[] outbuf, int outoff)
off
- The index of the first element in the stream to
copy.len
- The number of elements of the array to copyoutbuf
- The destination arrayoutoff
- The index of the first element in 'outbuf' where
to write the data.public int size()
public void reset()
public int getByte(int pos)
pos
- The position of the byte to returnCopyright © 2015–2022 SCIFIO. All rights reserved.