com.Ostermiller.util
Class CircularCharBuffer.CircularCharBufferReader

java.lang.Object
  extended by java.io.Reader
      extended by com.Ostermiller.util.CircularCharBuffer.CircularCharBufferReader
All Implemented Interfaces:
java.io.Closeable, java.lang.Readable
Enclosing class:
CircularCharBuffer

protected class CircularCharBuffer.CircularCharBufferReader
extends java.io.Reader

Class for reading from a circular character buffer.

Since:
ostermillerutils 1.00.00

Field Summary
 
Fields inherited from class java.io.Reader
lock
 
Constructor Summary
protected CircularCharBuffer.CircularCharBufferReader()
           
 
Method Summary
 void close()
          Close the stream.
 void mark(int readAheadLimit)
          Mark the present position in the stream.
 boolean markSupported()
          Tell whether this stream supports the mark() operation.
 int read()
          Read a single character.
 int read(char[] cbuf)
          Read characters into an array.
 int read(char[] cbuf, int off, int len)
          Read characters into a portion of an array.
 boolean ready()
          Tell whether this stream is ready to be read.
 void reset()
          Reset the stream.
 long skip(long n)
          Skip characters.
 
Methods inherited from class java.io.Reader
read
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CircularCharBuffer.CircularCharBufferReader

protected CircularCharBuffer.CircularCharBufferReader()
Method Detail

close

public void close()
           throws java.io.IOException
Close the stream. Once a stream has been closed, further read(), ready(), mark(), or reset() invocations will throw an IOException. Closing a previously-closed stream, however, has no effect.

Specified by:
close in interface java.io.Closeable
Specified by:
close in class java.io.Reader
Throws:
java.io.IOException - never.
Since:
ostermillerutils 1.00.00

mark

public void mark(int readAheadLimit)
          throws java.io.IOException
Mark the present position in the stream. Subsequent calls to reset() will attempt to reposition the stream to this point.

The readAheadLimit must be less than the size of circular buffer.

Overrides:
mark in class java.io.Reader
Parameters:
readAheadLimit - Limit on the number of characters that may be read while still preserving the mark. After reading this many characters, attempting to reset the stream will fail.
Throws:
java.io.IOException - if the stream is closed, or the buffer size is greater than or equal to the readAheadLimit.
Since:
ostermillerutils 1.00.00

markSupported

public boolean markSupported()
Tell whether this stream supports the mark() operation.

Overrides:
markSupported in class java.io.Reader
Returns:
true, mark is supported.
Since:
ostermillerutils 1.00.00

read

public int read()
         throws java.io.IOException
Read a single character. This method will block until a character is available, an I/O error occurs, or the end of the stream is reached.

Overrides:
read in class java.io.Reader
Returns:
The character read, as an integer in the range 0 to 65535 (0x00-0xffff), or -1 if the end of the stream has been reached
Throws:
java.io.IOException - if the stream is closed.
Since:
ostermillerutils 1.00.00

read

public int read(char[] cbuf)
         throws java.io.IOException
Read characters into an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

Overrides:
read in class java.io.Reader
Parameters:
cbuf - Destination buffer.
Returns:
The number of characters read, or -1 if the end of the stream has been reached
Throws:
java.io.IOException - if the stream is closed.
Since:
ostermillerutils 1.00.00

read

public int read(char[] cbuf,
                int off,
                int len)
         throws java.io.IOException
Read characters into a portion of an array. This method will block until some input is available, an I/O error occurs, or the end of the stream is reached.

Specified by:
read in class java.io.Reader
Parameters:
cbuf - Destination buffer.
off - Offset at which to start storing characters.
len - Maximum number of characters to read.
Returns:
The number of characters read, or -1 if the end of the stream has been reached
Throws:
java.io.IOException - if the stream is closed.
Since:
ostermillerutils 1.00.00

ready

public boolean ready()
              throws java.io.IOException
Tell whether this stream is ready to be read.

Overrides:
ready in class java.io.Reader
Returns:
True if the next read() is guaranteed not to block for input, false otherwise. Note that returning false does not guarantee that the next read will block.
Throws:
java.io.IOException - if the stream is closed.
Since:
ostermillerutils 1.00.00

reset

public void reset()
           throws java.io.IOException
Reset the stream. If the stream has been marked, then attempt to reposition i at the mark. If the stream has not been marked, or more characters than the readAheadLimit have been read, this method has no effect.

Overrides:
reset in class java.io.Reader
Throws:
java.io.IOException - if the stream is closed.
Since:
ostermillerutils 1.00.00

skip

public long skip(long n)
          throws java.io.IOException,
                 java.lang.IllegalArgumentException
Skip characters. This method will block until some characters are available, an I/O error occurs, or the end of the stream is reached.

Overrides:
skip in class java.io.Reader
Parameters:
n - The number of characters to skip
Returns:
The number of characters actually skipped
Throws:
java.lang.IllegalArgumentException - if n is negative.
java.io.IOException - if the stream is closed.
Since:
ostermillerutils 1.00.00