com.Ostermiller.util
Class CircularByteBuffer.CircularByteBufferInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by com.Ostermiller.util.CircularByteBuffer.CircularByteBufferInputStream
All Implemented Interfaces:
java.io.Closeable
Enclosing class:
CircularByteBuffer

protected class CircularByteBuffer.CircularByteBufferInputStream
extends java.io.InputStream

Class for reading from a circular byte buffer.

Since:
ostermillerutils 1.00.00

Constructor Summary
protected CircularByteBuffer.CircularByteBufferInputStream()
           
 
Method Summary
 int available()
          Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream.
 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 byte.
 int read(byte[] cbuf)
          Read bytes into an array.
 int read(byte[] cbuf, int off, int len)
          Read bytes into a portion of an array.
 void reset()
          Reset the stream.
 long skip(long n)
          Skip bytes.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CircularByteBuffer.CircularByteBufferInputStream

protected CircularByteBuffer.CircularByteBufferInputStream()
Method Detail

available

public int available()
              throws java.io.IOException
Returns the number of bytes that can be read (or skipped over) from this input stream without blocking by the next caller of a method for this input stream. The next caller might be the same thread or or another thread.

Overrides:
available in class java.io.InputStream
Returns:
the number of bytes that can be read from this input stream without blocking.
Throws:
java.io.IOException - if the stream is closed.
Since:
ostermillerutils 1.00.00

close

public void close()
           throws java.io.IOException
Close the stream. Once a stream has been closed, further read(), available(), 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
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException - never.
Since:
ostermillerutils 1.00.00

mark

public void mark(int readAheadLimit)
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, otherwise this method has no effect.

Overrides:
mark in class java.io.InputStream
Parameters:
readAheadLimit - Limit on the number of bytes that may be read while still preserving the mark. After reading this many bytes, attempting to reset the stream will fail.
Since:
ostermillerutils 1.00.00

markSupported

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

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

read

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

Specified by:
read in class java.io.InputStream
Returns:
The byte read, as an integer in the range 0 to 255 (0x00-0xff), 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(byte[] cbuf)
         throws java.io.IOException
Read bytes 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.InputStream
Parameters:
cbuf - Destination buffer.
Returns:
The number of bytes 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(byte[] cbuf,
                int off,
                int len)
         throws java.io.IOException
Read bytes 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.

Overrides:
read in class java.io.InputStream
Parameters:
cbuf - Destination buffer.
off - Offset at which to start storing bytes.
len - Maximum number of bytes to read.
Returns:
The number of bytes 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

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 bytes than the readAheadLimit have been read, this method has no effect.

Overrides:
reset in class java.io.InputStream
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 bytes. This method will block until some bytes are available, an I/O error occurs, or the end of the stream is reached.

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