org.apache.hc.core5.http.io

## Class EofSensorInputStream

- java.lang.Object
- - java.io.InputStream
  - - org.apache.hc.core5.http.io.EofSensorInputStream

- All Implemented Interfaces:
    Closeable, AutoCloseable

      public class EofSensorInputStream
      extends InputStream

  A stream wrapper that triggers actions on `close()` and EOF. Primarily used to auto-release an underlying managed connection when the response body is consumed or no longer needed.
  Since:
    4.0
  See Also:
    `EofSensorWatcher`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `EofSensorInputStream(InputStream in, EofSensorWatcher watcher)` Creates a new EOF sensor.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `abort()` Aborts this stream.
    `int` | `available()`
    `void` | `close()`
    `int` | `read()`
    `int` | `read(byte[] b)`
    `int` | `read(byte[] b, int off, int len)`

    - ### Methods inherited from class java.io.InputStream

      `mark, markSupported, reset, skip`

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

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

- - ### Constructor Detail

    - #### EofSensorInputStream

          public EofSensorInputStream(InputStream in,
                              EofSensorWatcher watcher)

      Creates a new EOF sensor. If no watcher is passed, the underlying stream will simply be closed when EOF is detected or `close` is called. Otherwise, the watcher decides whether the underlying stream should be closed before detaching from it.
      Parameters:
        `in` - the wrapped stream
        `watcher` - the watcher for events, or `null` for auto-close behavior without notification

  - ### Method Detail

    - #### read

          public int read()
                   throws IOException

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

    - #### 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`

    - #### 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`

    - #### abort

          public void abort()
                     throws IOException

      Aborts this stream. This is a special version of `close()` which prevents re-use of the underlying connection, if any. Calling this method indicates that there should be no attempt to read until the end of the stream.
      Throws:
        `IOException` - in case of an IO problem on closing the underlying stream

Copyright © 2005–2021 The Apache Software Foundation. All rights reserved.