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 anHttpMethod
object representing an HTTP connection.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description int
available()
void
close()
Standard input stream close method, except it ensures thatreleaseConnection()
is called before the input stream is closed.org.apache.commons.httpclient.HttpMethod
getHttpMethod()
Returns the underlying HttpMethod object that contains/manages the actual HTTP connection.InputStream
getWrappedInputStream()
int
read()
Standard input stream read method, except it callsreleaseConnection()
when the underlying input stream is consumed.int
read(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 anHttpMethod
object representing an HTTP connection. If a connection input stream is available, this constructor wraps the underlying input stream in anInterruptableInputStream
and makes that stream available. If no underlying connection is available, an emptyByteArrayInputStream
is 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 IOException
Standard input stream read method, except it callsreleaseConnection()
when the underlying input stream is consumed.- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
public int read(byte[] b, int off, int len) throws IOException
Standard input stream read method, except it callsreleaseConnection()
when the underlying input stream is consumed.- Overrides:
read
in classInputStream
- Throws:
IOException
-
available
public int available() throws IOException
- Overrides:
available
in classInputStream
- Throws:
IOException
-
close
public void close() throws IOException
Standard input stream close method, except it ensures thatreleaseConnection()
is called before the input stream is closed.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classInputStream
- Throws:
IOException
-
getWrappedInputStream
public InputStream getWrappedInputStream()
- Specified by:
getWrappedInputStream
in interfaceInputStreamWrapper
- Returns:
- the underlying input stream wrapped by this class.
-
-