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 Summary
Constructors Constructor Description HttpMethodReleaseInputStream(org.apache.commons.httpclient.HttpMethod httpMethod)Constructs an input stream based on anHttpMethodobject representing an HTTP connection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intavailable()voidclose()Standard input stream close method, except it ensures thatreleaseConnection()is called before the input stream is closed.org.apache.commons.httpclient.HttpMethodgetHttpMethod()Returns the underlying HttpMethod object that contains/manages the actual HTTP connection.InputStreamgetWrappedInputStream()intread()Standard input stream read method, except it callsreleaseConnection()when the underlying input stream is consumed.intread(byte[] b, int off, int len)Standard input stream read method, except it callsreleaseConnection()when the underlying input stream is consumed.-
Methods inherited from class java.io.InputStream
mark, markSupported, nullInputStream, read, readAllBytes, readNBytes, readNBytes, reset, skip, transferTo
-
-
-
-
Constructor Detail
-
HttpMethodReleaseInputStream
public HttpMethodReleaseInputStream(org.apache.commons.httpclient.HttpMethod httpMethod)
Constructs an input stream based on anHttpMethodobject representing an HTTP connection. If a connection input stream is available, this constructor wraps the underlying input stream in anInterruptableInputStreamand makes that stream available. If no underlying connection is available, an emptyByteArrayInputStreamis made available.- Parameters:
httpMethod-
-
-
Method Detail
-
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 IOExceptionStandard input stream read method, except it callsreleaseConnection()when the underlying input stream is consumed.- Specified by:
readin classInputStream- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOExceptionStandard input stream read method, except it callsreleaseConnection()when the underlying input stream is consumed.- Overrides:
readin classInputStream- Throws:
IOException
-
available
public int available() throws IOException- Overrides:
availablein classInputStream- Throws:
IOException
-
close
public void close() throws IOExceptionStandard input stream close method, except it ensures thatreleaseConnection()is called before the input stream is closed.- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Overrides:
closein classInputStream- Throws:
IOException
-
getWrappedInputStream
public InputStream getWrappedInputStream()
- Specified by:
getWrappedInputStreamin interfaceInputStreamWrapper- Returns:
- the underlying input stream wrapped by this class.
-
-