org.dellroad.stuff.io
Class InputStreamReader

java.lang.Object
  extended by org.dellroad.stuff.io.InputStreamReader

public class InputStreamReader
extends Object

Reads zero or more InputStreams serialized inside an underlying InputStream by an OutputStreamWriter.

Instances of this class are thread safe, as are the InputStreams returned by read().

See Also:
OutputStreamWriter

Constructor Summary
InputStreamReader(InputStream input)
          Constructor.
 
Method Summary
 void close()
          Close this instance.
 InputStream read()
          Read the next InputStream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

InputStreamReader

public InputStreamReader(InputStream input)
Constructor.

Parameters:
input - the underlying InputStream that will carry nested InputStreams within it
Method Detail

read

public InputStream read()
                 throws IOException
Read the next InputStream.

The returned InputStream will remain valid as long as it has not been closed, the underlying input has not been closed, and no subsequent invocation of this method has been made. As soon as any of those events occurs, all subsequent accesses to the previously returned InputStream will throw an exception.

The returned InputStream may be closed prior to its EOF, in which case any remaining bytes will be skipped over during the next invocation of this method.

Note: while any thread is blocked reading from the returned InputStream, this method will block as well.

Throws:
IOException - if this instance is closed
IOException - if the underlying InputStream has thrown an exception
return - the next InputStream, or null if EOF has been reached on the underlying input

close

public void close()
           throws IOException
Close this instance. Does nothing if already closed.

This closes the underlying input; however, if the InputStream most recently returned from read() is still open, the close of the underlying input will be postponed until it is no longer open.

Throws:
IOException - if an there is an error closing the underlying InputStream