Class HttpMethodReleaseInputStream

java.lang.Object
java.io.InputStream
org.jets3t.service.impl.rest.httpclient.HttpMethodReleaseInputStream
All Implemented Interfaces:
Closeable, AutoCloseable, InputStreamWrapper

public class HttpMethodReleaseInputStream extends InputStream implements InputStreamWrapper
Utility class to wrap InputStreams obtained from an HttpClient library's HttpMethod object, and ensure the stream and HTTP connection is cleaned up properly.

This input stream wrapper is used to ensure that input streams obtained through HttpClient connections are cleaned up correctly once the caller has read all the contents of the connection's input stream, or closed that input stream.

Important! This input stream must be completely consumed or closed to ensure the necessary cleanup operations can be performed.

Author:
James Murty
  • Constructor Details

    • HttpMethodReleaseInputStream

      public HttpMethodReleaseInputStream(org.apache.commons.httpclient.HttpMethod httpMethod)
      Constructs an input stream based on an HttpMethod object representing an HTTP connection. If a connection input stream is available, this constructor wraps the underlying input stream in an InterruptableInputStream and makes that stream available. If no underlying connection is available, an empty ByteArrayInputStream is made available.
      Parameters:
      httpMethod -
  • Method Details

    • getHttpMethod

      public org.apache.commons.httpclient.HttpMethod getHttpMethod()
      Returns the underlying HttpMethod object that contains/manages the actual HTTP connection.
      Returns:
      the HTTPMethod object that provides the data input stream.
    • read

      public int read() throws IOException
      Standard input stream read method, except it calls releaseConnection() when the underlying input stream is consumed.
      Specified by:
      read in class InputStream
      Throws:
      IOException
    • read

      public int read(byte[] b, int off, int len) throws IOException
      Standard input stream read method, except it calls releaseConnection() when the underlying input stream is consumed.
      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
      Standard input stream close method, except it ensures that releaseConnection() is called before the input stream is closed.
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Overrides:
      close in class InputStream
      Throws:
      IOException
    • getWrappedInputStream

      public InputStream getWrappedInputStream()
      Specified by:
      getWrappedInputStream in interface InputStreamWrapper
      Returns:
      the underlying input stream wrapped by this class.