Package picard.util
Class CircularByteBuffer
java.lang.Object
picard.util.CircularByteBuffer
Implementation of a circular byte buffer that uses a large byte[] internally and supports basic
read/write operations from/to other byte[]s passed as arguments. Uses wait/nofity() to manage
cross-thread coordination when the buffer is either full or empty.
-
Constructor Summary
ConstructorsConstructorDescriptionCircularByteBuffer
(int size) Constructs a buffer capable of holding the given number of bytes. -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Signals that the buffer is closed and no further writes will occur.int
Returns the number of bytes that are in the buffer at the time of the method invocation.int
Returns the total capacity of the buffer (empty+filled).boolean
isClosed()
Returns true if the buffer is closed, false otherwise.int
read
(byte[] bytes, int start, int size) Read bytes from the buffer into the supplied array.int
write
(byte[] bytes, int start, int size) Write bytes into the buffer from the supplied array.
-
Constructor Details
-
CircularByteBuffer
public CircularByteBuffer(int size) Constructs a buffer capable of holding the given number of bytes.
-
-
Method Details
-
write
public int write(byte[] bytes, int start, int size) Write bytes into the buffer from the supplied array. Will attempt to read 'size' bytes beginning at 'start' in the supplied array and copy them into the buffer. If the buffer is near full or cannot write 'size' bytes contiguously it may write fewer than 'size' bytes.- Returns:
- the number of bytes read from the input array and copied into the buffer
-
read
public int read(byte[] bytes, int start, int size) Read bytes from the buffer into the supplied array. Will attempt to read 'size' bytes and write them into the supplied array beginning at index 'start' in the supplied array. If the buffer is near empty or cannot read 'size' bytes contiguously it may write fewer than 'size' bytes.- Returns:
- the number of bytes read from the buffer and copied into the input array
-
close
public void close()Signals that the buffer is closed and no further writes will occur. -
isClosed
public boolean isClosed()Returns true if the buffer is closed, false otherwise. -
getCapacity
public int getCapacity()Returns the total capacity of the buffer (empty+filled). -
getBytesAvailableToRead
public int getBytesAvailableToRead()Returns the number of bytes that are in the buffer at the time of the method invocation.
-