net.sf.logdistiller.util
Class BufferingReader
java.lang.Object
java.io.Reader
net.sf.logdistiller.util.BufferingReader
- All Implemented Interfaces:
- Closeable, Readable
public class BufferingReader
- extends Reader
A reader reading its content from another reader, but buffering the data to be able to give it back on demand. When
data is given back, it is not maintained in memory any more. When using this class, take care to get data regularly,
or all the data read will stay in memory, risking OutOfMemoryException !
- See Also:
freeData(int)
Method Summary |
void |
close()
|
String |
freeData(int count)
Get some data that have been buffered, and free corresponding space in the buffer. |
int |
getBufferSize()
Get the size of the buffer. |
int |
getDataLength()
Get the length of data available in the buffer. |
int |
read(char[] cbuf,
int off,
int len)
|
boolean |
ready()
|
void |
shrinkBuffer()
Shrink the buffer to its minimal size to store actual data. |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
BufferingReader
public BufferingReader(Reader reader,
int bufferBlockSize)
BufferingReader
public BufferingReader(Reader reader)
ready
public boolean ready()
throws IOException
- Overrides:
ready
in class Reader
- Throws:
IOException
close
public void close()
throws IOException
- Specified by:
close
in interface Closeable
- Specified by:
close
in class Reader
- Throws:
IOException
read
public int read(char[] cbuf,
int off,
int len)
throws IOException
- Specified by:
read
in class Reader
- Throws:
IOException
getDataLength
public int getDataLength()
- Get the length of data available in the buffer.
- Returns:
- available data length
freeData
public String freeData(int count)
- Get some data that have been buffered, and free corresponding space in the buffer.
- Parameters:
count
- the number of characters to get
- Returns:
- the corresponding data
- Throws:
IndexOutOfBoundsException
- if the amount of data asked is more than what is available in the buffer- See Also:
getDataLength()
getBufferSize
public int getBufferSize()
- Get the size of the buffer.
- Returns:
- the buffer size
shrinkBuffer
public void shrinkBuffer()
- Shrink the buffer to its minimal size to store actual data. In normal use, the buffer grows as needed but never
shrinks.
Copyright © 2004-2009. All Rights Reserved.