|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.sf.japaki.io.RingBuffer
public class RingBuffer
A ring buffer stores the characters read from the input stream in a buffer. The last read characters overwrite the oldest data in the buffer.
n
characters read from the input stream,
where n
is the buffer's capacity.
offset
is the location of the buffer's first character in the
input stream.offset
to offset+position
.offset-n+position
to offset-1
.
Constructor Summary | |
---|---|
RingBuffer(Reader in)
Constructs a new RingBuffer with a default buffer size. |
|
RingBuffer(Reader in,
int sz)
Constructs a new RingBuffer. |
Method Summary | |
---|---|
void |
close()
|
void |
free(int pos)
Frees the buffer before the specified position. |
int |
read(char[] cbuf,
int off,
int len,
int pos)
Retrieves a sequence of characters as described in . |
String |
toString()
|
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Constructor Detail |
---|
public RingBuffer(Reader in, int sz)
in
- base readersz
- size to be allocated for the underlying buffer
NullPointerException
- if in
is null
IllegalArgumentException
- if the size is a negative integerpublic RingBuffer(Reader in)
in
- base reader
NullPointerException
- if in
is null
Method Detail |
---|
public int read(char[] cbuf, int off, int len, int pos) throws IOException
ReaderBuffer
read
.
read
in interface ReaderBuffer
cbuf
- Destination bufferoff
- Offset at which to start storing characterslen
- Maximum number of characters to readpos
- Position, where to start reading in the stream
IOException
- If the specified position is not covered by
the underlying buffer or
if an I/O error occurspublic void free(int pos)
ReaderBuffer
free
in interface ReaderBuffer
pos
- All characters before this position may no longer be stored
in the underlying buffer.
Actual behaviour depends on the implementation.public void close() throws IOException
close
in interface Closeable
IOException
public String toString()
toString
in class Object
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |