public class ByteInputBuffer extends Object
Unlike the ByteArrayInputStream this class is not thread safe (i.e. no two threads can use the same object at the same time, but different objects may be used in different threads).
This class can modify the contents of the buffer given to the constructor, when the addByteArray() method is called.
InputStream
Modifier and Type | Field and Description |
---|---|
private byte[] |
buf
The byte array containing the data
|
private int |
count
The index one greater than the last valid character in the input
stream buffer
|
private int |
pos
The index of the next character to read from the input stream buffer
|
Constructor and Description |
---|
ByteInputBuffer(byte[] buf)
Creates a new byte array input stream that reads data from the
specified byte array.
|
ByteInputBuffer(byte[] buf,
int offset,
int length)
Creates a new byte array input stream that reads data from the
specified byte array.
|
Modifier and Type | Method and Description |
---|---|
void |
addByteArray(byte[] data,
int off,
int len)
Adds the specified data to the end of the byte array stream.
|
int |
read()
Reads the next byte of data from this input stream.
|
int |
readChecked()
Reads the next byte of data from this input stream.
|
void |
setByteArray(byte[] buf,
int offset,
int length)
Sets the underlying buffer byte array to the given one, with the given
offset and length.
|
private byte[] buf
private int count
private int pos
public ByteInputBuffer(byte[] buf)
buf
- the input buffer.public ByteInputBuffer(byte[] buf, int offset, int length)
The byte array is not copied.
buf
- the input buffer.offset
- the offset in the buffer of the first byte to
read.length
- the maximum number of bytes to read from the
buffer.public void setByteArray(byte[] buf, int offset, int length)
The byte array is not copied.
buf
- the input buffer. If null it is the current input buffer.offset
- the offset in the buffer of the first byte to read. If
negative it is assumed to be the byte just after the end of the current
input buffer, only permitted if 'buf' is null.length
- the maximum number of bytes to read frmo the buffer.public void addByteArray(byte[] data, int off, int len)
data
- The data to add. The data is copied.off
- The index, in data, of the first element to add to
the stream.len
- The number of elements to add to the array.public int readChecked() throws IOException
This method is not synchronized, so it is not thread safe.
EOFException
- If the end of the stream is reached.IOException
public int read()
This method is not synchronized, so it is not thread safe.
Copyright © 2016 Open Microscopy Environment