java.lang.Object | |
↳ | com.pnfsoftware.jeb.util.collect.BytePipe |
A dynamic byte array (pipe). Bytes are written/appended at the end; bytes are read from the beginning. Reading methods raise if the number of requested bytes is more than what is available in the array.
This class is thread-safe for a single producer thread, single consumer thread. If there are multiple producers and/or multiple consumers, client code is responsible for making sure that writer threads coordinate among themselves, and that reader threads do the same as well. Ideally (and most likely), client code should have a single writer thread, and one reader thread (same or different as the writer's).
Public Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
BytePipe()
Create an array whose initial capacity if 4,096 bytes.
| |||||||||||
BytePipe(int initialCapacity)
Create an array with the provided initial capacity.
|
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
synchronized void |
append(byte[] data)
Append bytes to this array.
| ||||||||||
synchronized void |
append(byte[] data, int offset, int length)
Append bytes to this array.
| ||||||||||
synchronized void |
append(int b)
Append a single byte to this dynamic array.
| ||||||||||
synchronized void |
append(byte b)
Append a single byte to this dynamic array.
| ||||||||||
int |
available()
Get the number of bytes available for reading.
| ||||||||||
int |
blockUntilAvailable(int n, long timeout)
Wait until enough data is available for reading.
| ||||||||||
int |
capacity()
Get the current capacity of the array.
| ||||||||||
synchronized int |
get()
Retrieve a single byte.
| ||||||||||
synchronized void |
get(byte[] data)
Get a specified amount of bytes.
| ||||||||||
synchronized void |
get(byte[] data, int offset, int size)
Get a specified amount of bytes.
| ||||||||||
synchronized byte[] |
getAll()
Read all available bytes.
| ||||||||||
int |
limit()
Get the number of bytes in the pipe.
| ||||||||||
synchronized byte |
peek()
Peek a single byte within this array.
| ||||||||||
synchronized void |
peek(byte[] data, int where, int size)
Peek into this array for a specified amount of data.
| ||||||||||
synchronized void |
peek(byte[] data)
Peek into this array.
| ||||||||||
int |
position()
Get the current position in the pipe.
| ||||||||||
int |
readWait(long timeout)
Read a single byte of data.
| ||||||||||
synchronized void |
reset()
Reset this array: the number of bytes available for reading becomes 0.
| ||||||||||
synchronized void |
skip(int n)
Skip bytes.
|
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class
java.lang.Object
|
Create an array whose initial capacity if 4,096 bytes.
Create an array with the provided initial capacity.
initialCapacity | strictly positive number |
---|
Append bytes to this array.
Append bytes to this array.
Append a single byte to this dynamic array.
Append a single byte to this dynamic array.
Get the number of bytes available for reading.
Wait until enough data is available for reading.
n | size in bytes |
---|---|
timeout | in milliseconds (0 means infinite) |
Get the current capacity of the array. Note: the capacity varies as bytes are written/read to the array.
Retrieve a single byte. Throws if there is nothing available.
Get a specified amount of bytes. Throws if not enough bytes are available.
Get a specified amount of bytes. Throws if not enough bytes are available.
Read all available bytes.
Get the number of bytes in the pipe.
Peek a single byte within this array. Throws if there a byte is not available.
Peek into this array for a specified amount of data. Throws if not enough bytes are available.
Peek into this array. Throws if not enough bytes are available.
Get the current position in the pipe.
Read a single byte of data. This method is blocking.
timeout | in milliseconds; 0 means infinite |
---|
Reset this array: the number of bytes available for reading becomes 0.
Skip bytes. Throws if not enough bytes are available.