org.modeshape.common.util

## Class SelfClosingInputStream

- java.lang.Object
- - java.io.InputStream
  - - org.modeshape.common.util.SelfClosingInputStream

- All Implemented Interfaces:
    Closeable, AutoCloseable

      @NotThreadSafe
      public class SelfClosingInputStream
      extends InputStream

  An `InputStream` implementation that wraps another stream and makes sure that `InputStream.close()` is always called on the wrapped stream when there is no more content to read or when an unexpected exception occurs.

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `SelfClosingInputStream(InputStream stream)` Create a self-closing `InputStream` that wraps another input stream.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `available()`
    `void` | `close()`
    `int` | `hashCode()`
    `void` | `mark(int readlimit)`
    `boolean` | `markSupported()`
    `int` | `read()`
    `int` | `read(byte[] b)`
    `int` | `read(byte[] b, int off, int len)`
    `void` | `reset()`
    `long` | `skip(long n)`
    `String` | `toString()`
    `InputStream` | `wrappedStream()` Returns the stream that this instance wraps.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, notify, notifyAll, wait, wait, wait`

- - ### Constructor Detail

    - #### SelfClosingInputStream

          public SelfClosingInputStream(InputStream stream)

      Create a self-closing `InputStream` that wraps another input stream.
      Parameters:
        `stream` - the wrapped `InputStream`; may not be null.

  - ### Method Detail

    - #### available

          public int available()
                        throws IOException

      Overrides:
        `available` in class `InputStream`
      Throws:
        `IOException`

    - #### close

          public void close()
                     throws IOException

      Specified by:
        `close` in interface `Closeable`
      Specified by:
        `close` in interface `AutoCloseable`
      Overrides:
        `close` in class `InputStream`
      Throws:
        `IOException`

    - #### hashCode

          public int hashCode()

      Overrides:
        `hashCode` in class `Object`

    - #### mark

          public void mark(int readlimit)

      Overrides:
        `mark` in class `InputStream`

    - #### markSupported

          public boolean markSupported()

      Overrides:
        `markSupported` in class `InputStream`

    - #### read

          public int read(byte[] b,
                 int off,
                 int len)
                   throws IOException

      Overrides:
        `read` in class `InputStream`
      Throws:
        `IOException`

    - #### read

          public int read(byte[] b)
                   throws IOException

      Overrides:
        `read` in class `InputStream`
      Throws:
        `IOException`

    - #### read

          public int read()
                   throws IOException

      Specified by:
        `read` in class `InputStream`
      Throws:
        `IOException`

    - #### reset

          public void reset()
                     throws IOException

      Overrides:
        `reset` in class `InputStream`
      Throws:
        `IOException`

    - #### skip

          public long skip(long n)
                    throws IOException

      Overrides:
        `skip` in class `InputStream`
      Throws:
        `IOException`

    - #### toString

          public String toString()

      Overrides:
        `toString` in class `Object`

    - #### wrappedStream

          public InputStream wrappedStream()

      Returns the stream that this instance wraps.
      Returns:
        an `InputStream` instance, never null.

Copyright © 2008-2014 JBoss, a division of Red Hat. All Rights Reserved.