com.petersalomonsen.jjack.javasound
Class BlockingByteFIFO

java.lang.Object
  extended by com.petersalomonsen.jjack.javasound.BlockingByteFIFO

public class BlockingByteFIFO
extends java.lang.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
(package private)  boolean blocking
           
(package private)  byte[] buffer
           
(package private)  long bufferPosRead
           
(package private)  long bufferPosWrite
           
 
Constructor Summary
BlockingByteFIFO(int size)
           
 
Method Summary
 int availableRead()
           
 int availableWrite()
           
private  void block()
           
 void flush()
          Discard unread data
 long getBufferPosRead()
           
 long getBufferPosWrite()
           
 int getBufferSize()
          Return the size of the buffer
 int read(byte[] b, int off, int len)
          Read into provided byteArray - will block until all data is read
private  int readLenOrAvailable(byte[] b, int off, int len)
          Read all requested amount of data, or the maximum that is available for reading
private  void unblock()
           
 int write(byte[] b, int off, int len)
          Write data of provided bytearray.
private  int writeLenOrAvailable(byte[] b, int off, int len)
          Write all requested amount of data, or the maximum that is available for writing
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

buffer

byte[] buffer

bufferPosWrite

long bufferPosWrite

bufferPosRead

long bufferPosRead

blocking

boolean blocking
Constructor Detail

BlockingByteFIFO

public BlockingByteFIFO(int size)
Method Detail

availableRead

public int availableRead()

availableWrite

public int availableWrite()

read

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


write

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


getBufferPosRead

public long getBufferPosRead()
Returns:
the bufferPosRead

getBufferPosWrite

public long getBufferPosWrite()
Returns:
the bufferPosWrite

getBufferSize

public int getBufferSize()
Return the size of the buffer


flush

public void flush()
Discard unread data


unblock

private void unblock()

block

private void block()

readLenOrAvailable

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


writeLenOrAvailable

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