Class InputStreamReader

java.lang.Object
org.dellroad.stuff.io.InputStreamReader
All Implemented Interfaces:
Closeable, AutoCloseable

public class InputStreamReader extends Object implements Closeable
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:
  • Constructor Details

    • InputStreamReader

      public InputStreamReader(InputStream input)
      Constructor.
      Parameters:
      input - the underlying InputStream that will carry nested InputStreams within it
  • Method Details

    • 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.

      Returns:
      the next InputStream, or null if EOF has been reached on the underlying input
      Throws:
      IOException - if this instance is closed
      IOException - if the underlying InputStream has thrown an exception
    • 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.

      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException - if an there is an error closing the underlying InputStream