|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.groovemanager.tools.RingBuffer
A RingBuffer represents a buffer that has a read and a write position which are set back to 0 when the end is reached. Buffer underruns or overflows are avoided by only allowing writing or reading aslong as there are enough bytes available for the deired operation. As one can expect that reader and writer will be different threads, this implementation is synchronized where needed.
| Field Summary | |
|---|---|
private int |
granularity
The granularity in which data must be read or written. |
private boolean |
open
Indicates whether this buffer is in open state or not |
private java.nio.ByteBuffer |
readBuffer
A view to the source buffer used for reading |
private boolean |
writeAhead
When read and write position are the same, this value indicates, whether the buffer is filled completely (false) or emptied completely (true) |
private java.nio.ByteBuffer |
writeBuffer
A view to the source buffer used for reading |
| Constructor Summary | |
|---|---|
RingBuffer(byte[] buffer,
int offset,
int length,
int granularity)
Construct a new RingBuffer out of the specified part of the given byte array |
|
RingBuffer(java.nio.ByteBuffer buffer,
int granularity)
Construct a new RingBuffer out of the given buffer |
|
| Method Summary | |
|---|---|
void |
close()
Close this buffer |
void |
flush()
Empty this buffer |
boolean |
isOpen()
Tells whether this buffer is currently open or not |
void |
open()
Open this buffer |
int |
read(byte[] b,
int off,
int len)
Try to read len bytes from this buffer starting at the
current position into b starting at position
off. |
int |
readAvailable()
Get the number of bytes currently available for reading |
int |
size()
Get this buffer´s total size |
int |
write(byte[] b,
int off,
int len)
Try to write len bytes from b starting at
index off into this buffer starting at the current position. |
int |
writeAvailable()
Get the number of bytes currently available for writing |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
private final int granularity
private boolean open
private final java.nio.ByteBuffer readBuffer
private boolean writeAhead
private final java.nio.ByteBuffer writeBuffer
| Constructor Detail |
|---|
public RingBuffer(byte[] buffer,
int offset,
int length,
int granularity)
buffer - The byte array that should be used as source of this bufferoffset - Start position inside the given arraylength - The length of the buffer to creategranularity - The buffer granularity in bytes
public RingBuffer(java.nio.ByteBuffer buffer,
int granularity)
buffer - The buffer to be used as source for this ring buffergranularity - The buffer granularity in bytes| Method Detail |
|---|
public void close()
public void flush()
public boolean isOpen()
public void open()
public int read(byte[] b,
int off,
int len)
len bytes from this buffer starting at the
current position into b starting at position
off. The currently avilable bytes will be read the number
of bytes read will be returned.
b - The byte array to transfer the data tooff - The offset inside the target arraylen - The number of bytes to read
public int readAvailable()
public int size()
public int write(byte[] b,
int off,
int len)
len bytes from b starting at
index off into this buffer starting at the current position.
This method will not return before the given number of bytes has been
written or the buffer has been closed. This means that if the given
number of bytes can not be written at once, this methods waits until
another thread empties the needed part of this buffer by reading from it.
b - The array containing the data to writeoff - Start position inside the given arraylen - The number of bytes to write
public int writeAvailable()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||