com.petersalomonsen.jjack.javasound

Class BlockingByteFIFO

public class BlockingByteFIFO extends Object

A FIFO byte buffer that blocks on read or write if trying to read or write more than is available for reading/writing.

Version: 0.3

Author: Peter Johan Salomonsen

Field Summary
booleanblocking
byte[]buffer
longbufferPosRead
longbufferPosWrite
Constructor Summary
BlockingByteFIFO(int size)
Method Summary
intavailableRead()
intavailableWrite()
voidblock()
voidflush()
Discard unread data
longgetBufferPosRead()
longgetBufferPosWrite()
intgetBufferSize()
Return the size of the buffer
intread(byte[] b, int off, int len)
Read into provided byteArray - will block until all data is read
intreadLenOrAvailable(byte[] b, int off, int len)
Read all requested amount of data, or the maximum that is available for reading
voidunblock()
intwrite(byte[] b, int off, int len)
Write data of provided bytearray.
intwriteLenOrAvailable(byte[] b, int off, int len)
Write all requested amount of data, or the maximum that is available for writing

Field Detail

blocking

boolean blocking

buffer

byte[] buffer

bufferPosRead

long bufferPosRead

bufferPosWrite

long bufferPosWrite

Constructor Detail

BlockingByteFIFO

public BlockingByteFIFO(int size)

Method Detail

availableRead

public int availableRead()

availableWrite

public int availableWrite()

block

private void block()

flush

public void flush()
Discard unread data

getBufferPosRead

public long getBufferPosRead()

Returns: the bufferPosRead

getBufferPosWrite

public long getBufferPosWrite()

Returns: the bufferPosWrite

getBufferSize

public int getBufferSize()
Return the size of the buffer

read

public int read(byte[] b, int off, int len)
Read into provided byteArray - will block until all data is read

readLenOrAvailable

private int readLenOrAvailable(byte[] b, int off, int len)
Read all requested amount of data, or the maximum that is available for reading

unblock

private void unblock()

write

public int write(byte[] b, int off, int len)
Write data of provided bytearray. Will block until all data is written.

writeLenOrAvailable

private int writeLenOrAvailable(byte[] b, int off, int len)
Write all requested amount of data, or the maximum that is available for writing