Class EofSensorInputStream

  • All Implemented Interfaces:
    java.io.Closeable, java.lang.AutoCloseable, ConnectionReleaseTrigger

    public class EofSensorInputStream
    extends java.io.InputStream
    implements ConnectionReleaseTrigger
    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
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      void abortConnection()
      Aborts this stream.
      int available()  
      void close()  
      int read()  
      int read​(byte[] b)  
      int read​(byte[] b, int off, int len)  
      void releaseConnection()
      Same as close().
      • Methods inherited from class java.io.InputStream

        mark, markSupported, nullInputStream, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • EofSensorInputStream

        public EofSensorInputStream​(java.io.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 java.io.IOException
        Specified by:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b,
                        int off,
                        int len)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • read

        public int read​(byte[] b)
                 throws java.io.IOException
        Overrides:
        read in class java.io.InputStream
        Throws:
        java.io.IOException
      • available

        public int available()
                      throws java.io.IOException
        Overrides:
        available in class java.io.InputStream
        Throws:
        java.io.IOException
      • close

        public void close()
                   throws java.io.IOException
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface java.io.Closeable
        Overrides:
        close in class java.io.InputStream
        Throws:
        java.io.IOException
      • releaseConnection

        public void releaseConnection()
                               throws java.io.IOException
        Same as close().
        Specified by:
        releaseConnection in interface ConnectionReleaseTrigger
        Throws:
        java.io.IOException - in case of an IO problem. The connection will be released anyway.
      • abortConnection

        public void abortConnection()
                             throws java.io.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.
        Specified by:
        abortConnection in interface ConnectionReleaseTrigger
        Throws:
        java.io.IOException - in case of an IO problem. The connection will be released anyway.