org.jasen.io
Class NonBlockingStreamReader

java.lang.Object
  extended byorg.jasen.io.NonBlockingStreamReader

public class NonBlockingStreamReader
extends Object

Implements a threaded input stream reader which can be terminated if it blocks for too long.

Author:
Jason Polites

Constructor Summary
NonBlockingStreamReader()
           
NonBlockingStreamReader(StreamReaderListener streamReaderListener)
           
 
Method Summary
 void read(InputStream in, OutputStream out, int bufferSize, long timeout, byte[] terminator)
          Reads from the specified stream with the give buffer size and writes to the specified output stream.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

NonBlockingStreamReader

public NonBlockingStreamReader()

NonBlockingStreamReader

public NonBlockingStreamReader(StreamReaderListener streamReaderListener)
Method Detail

read

public void read(InputStream in,
                 OutputStream out,
                 int bufferSize,
                 long timeout,
                 byte[] terminator)
          throws IOException
Reads from the specified stream with the give buffer size and writes to the specified output stream.

If the reader blocks on a read() call for more than timeout milliseconds, the read process is abnormally aborted and an IOException is thrown

Parameters:
in - The inputstream from which to read
out - The outputstream to which to write
bufferSize - The size of the buffer (in bytes) to use when reading/writing
timeout - The timeout (in milliseconds) to allow the read to block until bytes are available from the stream
Throws:
IOException - If an error occurred while reading the stream, or the read timed out