class FifoBuffer
extends java.lang.Object
Modifier and Type | Class and Description |
---|---|
(package private) static class |
FifoBuffer.Page
Unit of buffer, singly linked and lazy created as needed.
|
(package private) class |
FifoBuffer.Pointer
Points to a specific byte in a
FifoBuffer.Page . |
Modifier and Type | Field and Description |
---|---|
private boolean |
closed
Set to true when the writer closes the write end.
|
private int |
limit
Cap to the # of bytes that we can hold.
|
private java.lang.Object |
lock |
private int |
pageSize |
private FifoBuffer.Pointer |
r
The position at which the next read/write will happen.
|
private int |
sz
Number of bytes currently in this ring buffer
|
private FifoBuffer.Pointer |
w
The position at which the next read/write will happen.
|
Constructor and Description |
---|
FifoBuffer(int pageSize,
int limit) |
FifoBuffer(java.lang.Object lock,
int pageSize,
int limit) |
Modifier and Type | Method and Description |
---|---|
void |
close() |
private FifoBuffer.Page |
newPage() |
int |
read(byte[] buf,
int start,
int len) |
(package private) int |
readable()
Number of bytes readable
|
private void |
releaseRing()
If the ring is no longer needed, release the buffer.
|
void |
setLimit(int newLimit) |
(package private) int |
writable()
Number of bytes writable
|
void |
write(byte[] buf,
int start,
int len) |
int |
writeTo(java.io.OutputStream out)
Write whatever readable to the specified OutputStream, then return.
|
private final java.lang.Object lock
private int sz
private int limit
private final int pageSize
private FifoBuffer.Pointer r
private FifoBuffer.Pointer w
private boolean closed
FifoBuffer(int pageSize, int limit)
FifoBuffer(java.lang.Object lock, int pageSize, int limit)
public void setLimit(int newLimit)
private FifoBuffer.Page newPage()
int readable()
int writable()
public void write(byte[] buf, int start, int len) throws java.lang.InterruptedException
java.lang.InterruptedException
public void close()
private void releaseRing()
public int read(byte[] buf, int start, int len) throws java.lang.InterruptedException
java.lang.InterruptedException
InputStream.read(byte[],int,int)
public int writeTo(java.io.OutputStream out) throws java.io.IOException
java.io.IOException