|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectcom.groovemanager.spi.asio.DoubleHalfRingBuffer
class DoubleHalfRingBuffer
A RingBuffer to be used with DoubleHalfBuffers.
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 DoubleHalfBuffer |
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 DoubleHalfBuffer |
writeBuffer
A view to the source buffer used for reading |
Constructor Summary | |
---|---|
DoubleHalfRingBuffer(DoubleHalfBuffer buffer,
int granularity)
Construct a new DoubleHalfRingBuffer 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 |
read(byte[] b,
int off,
int len,
boolean overwrite)
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 |
void |
rewind()
Rewind this buffer |
void |
setPositions(int readPos,
int writePos,
boolean writeAhead)
Set the read and write position of this Buffer |
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 |
write(byte[] b,
int off,
int len,
boolean overwrite)
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 boolean writeAhead
private boolean open
private final int granularity
private final DoubleHalfBuffer readBuffer
private final DoubleHalfBuffer writeBuffer
Constructor Detail |
---|
public DoubleHalfRingBuffer(DoubleHalfBuffer buffer, int granularity)
buffer
- The buffer to be used as source for this ring buffergranularity
- The buffer granularity in bytesMethod Detail |
---|
public int readAvailable()
public int writeAvailable()
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 read(byte[] b, int off, int len, boolean overwrite)
len
bytes from this buffer starting at the
current position into b
starting at position
off
. If overwrite
is true, the bytes will be
read independent of the number of available bytes for reading. If this
read operation exceeds the current write position (buffer underrun), the
write position will be discarded and set to the end of the read data.
b
- The byte array to transfer the data tooff
- The offset inside the target arraylen
- The number of bytes to readoverwrite
- true, if the given number of bytes should be read even
if this causes a buffer underrun
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 write(byte[] b, int off, int len, boolean overwrite)
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. If overwrite
is set
to true, this method will write the data immediately independent of the
number of bytes available for writing. If the read position is exceeded
by this operation (buffer overflow), the read position will be set after
the last written data.
b
- The array containing the data to writeoff
- Start position inside the given arraylen
- The number of bytes to writeoverwrite
- true, if the given number of bytes should be written
even if this causes a buffer overflow
public void open()
public boolean isOpen()
public void close()
public int size()
public void flush()
public void rewind()
public void setPositions(int readPos, int writePos, boolean writeAhead)
readPos
- The new read positionwritePos
- The new write positionwriteAhead
- Only needed, if readPos == writePos
:
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |