seda.nbio
Class NonblockingInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by seda.nbio.NonblockingInputStream
All Implemented Interfaces:
java.io.Closeable
Direct Known Subclasses:
MultiByteArrayInputStream, NonblockingSocketInputStream

public abstract class NonblockingInputStream
extends java.io.InputStream

A NonblockingInputStream is an InputStream which implements nonblocking semantics. The only additional method is nbRead() which performs a nonblocking read of one byte. The read(byte[]) and read(byte[], int, int) methods are also nonblocking. The standard read(byte) call is blocking as there is no way to indicate that nothing was read (a -1 means an error occurred).


Constructor Summary
NonblockingInputStream()
           
 
Method Summary
abstract  int available()
           
abstract  void close()
           
abstract  int nbRead()
          Perform a non-blocking read of one byte from this input stream.
abstract  int read()
          Perform a blocking read of one byte from this input stream.
abstract  int read(byte[] b)
          Perform a non-blocking read of up to b.length bytes from the underlying stream.
abstract  int read(byte[] b, int off, int len)
          Perform a non-blocking read of up to len bytes from the underlying stream into the byte array b starting at offset off.
abstract  long skip(long n)
          Skip n bytes of input.
 
Methods inherited from class java.io.InputStream
mark, markSupported, reset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NonblockingInputStream

public NonblockingInputStream()
Method Detail

read

public abstract int read()
                  throws java.io.IOException
Perform a blocking read of one byte from this input stream. Returns -1 if the end of the stream has been reached. Use nbRead() to perform a non-blocking read of one byte.

Specified by:
read in class java.io.InputStream
Throws:
java.io.IOException

nbRead

public abstract int nbRead()
                    throws java.io.IOException
Perform a non-blocking read of one byte from this input stream. Returns -1 if no data is available, or throws an EOFException if the end of the stream has been reached. Use read() to perform a blocking read of one byte.

Throws:
java.io.IOException

read

public abstract int read(byte[] b)
                  throws java.io.IOException
Perform a non-blocking read of up to b.length bytes from the underlying stream.

Overrides:
read in class java.io.InputStream
Returns:
The total number of bytes read into the buffer, 0 if no data was available, or -1 if the end of the stream has been reached.
Throws:
java.io.IOException

read

public abstract int read(byte[] b,
                         int off,
                         int len)
                  throws java.io.IOException
Perform a non-blocking read of up to len bytes from the underlying stream into the byte array b starting at offset off.

Overrides:
read in class java.io.InputStream
Returns:
The total number of bytes read into the buffer, 0 if no data was available, or -1 if the end of the stream has been reached.
Throws:
java.io.IOException

skip

public abstract long skip(long n)
                   throws java.io.IOException
Skip n bytes of input. This is a blocking operation.

Overrides:
skip in class java.io.InputStream
Throws:
java.io.IOException

available

public abstract int available()
                       throws java.io.IOException
Overrides:
available in class java.io.InputStream
Throws:
java.io.IOException

close

public abstract void close()
                    throws java.io.IOException
Specified by:
close in interface java.io.Closeable
Overrides:
close in class java.io.InputStream
Throws:
java.io.IOException