org.jvoicexml.client.text
Class NonBlockingObjectInputStream

java.lang.Object
  extended by java.io.InputStream
      extended by org.jvoicexml.client.text.NonBlockingObjectInputStream
All Implemented Interfaces:
Closeable

public final class NonBlockingObjectInputStream
extends InputStream

ObjectInputStream is not usable with Java new I/O. It requires a decoupling from the original stream.

This stream can be used in two ways

  1. read from an InputStream (see NonBlockingObjectInputStream(InputStream)) and
  2. read from a ReadableByteChannel (see NonBlockingObjectInputStream(ReadableByteChannel)).

Since:
0.6
Version:
$Revision: 2355 $
Author:
Dirk Schnelle-Walka

Constructor Summary
NonBlockingObjectInputStream(InputStream input)
          Constructs a new object with the given input stream as a source.
NonBlockingObjectInputStream(ReadableByteChannel channel)
          Constructs a new object.
 
Method Summary
 int available()
          
 int read()
          
 void read(SelectionKey key)
          Writes a piece of data that has been retrieved from a non blocking IO.
 Object readObject()
          Reads the next object from the input stream.
 
Methods inherited from class java.io.InputStream
close, mark, markSupported, read, read, reset, skip
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NonBlockingObjectInputStream

public NonBlockingObjectInputStream(InputStream input)
Constructs a new object with the given input stream as a source.

An object constructed using this constructor is intended to use the conventional way of reading from an iInputStream.

Parameters:
input - the input stream to read from.

NonBlockingObjectInputStream

public NonBlockingObjectInputStream(ReadableByteChannel channel)
Constructs a new object. In this case the data is obtained by a SelectionKey.

An object constructed using this constructor is intended to use non-blocking I/O. The maintainer of the ReadableByteChannel must feed the read buffer via the method read(SelectionKey).

Parameters:
channel - the channel to read from.
Method Detail

readObject

public Object readObject()
                  throws IOException,
                         ClassNotFoundException
Reads the next object from the input stream. The call blocks until the object is read.

Returns:
read object.
Throws:
IOException - Error reading
ClassNotFoundException - Unable to instantiate the object.

read

public void read(SelectionKey key)
          throws IOException
Writes a piece of data that has been retrieved from a non blocking IO.

Parameters:
key - selection key for reading.
Throws:
IOException - Error reading.

available

public int available()

Overrides:
available in class InputStream

read

public int read()
         throws IOException

Specified by:
read in class InputStream
Throws:
IOException


Copyright © 2005-2009JVoiceXML group.