Class HttpMethodReleaseInputStream
java.lang.Object
java.io.InputStream
org.jets3t.service.impl.rest.httpclient.HttpMethodReleaseInputStream
- All Implemented Interfaces:
Closeable
,AutoCloseable
,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
ConstructorsConstructorDescriptionHttpMethodReleaseInputStream
(org.apache.commons.httpclient.HttpMethod httpMethod) Constructs an input stream based on anHttpMethod
object representing an HTTP connection. -
Method Summary
Modifier and TypeMethodDescriptionint
void
close()
Standard input stream close method, except it ensures thatreleaseConnection()
is called before the input stream is closed.org.apache.commons.httpclient.HttpMethod
Returns the underlying HttpMethod object that contains/manages the actual HTTP connection.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, skipNBytes, transferTo
-
Constructor Details
-
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 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
Standard input stream read method, except it callsreleaseConnection()
when the underlying input stream is consumed.- Specified by:
read
in classInputStream
- Throws:
IOException
-
read
Standard input stream read method, except it callsreleaseConnection()
when the underlying input stream is consumed.- Overrides:
read
in classInputStream
- Throws:
IOException
-
available
- Overrides:
available
in classInputStream
- Throws:
IOException
-
close
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
- Specified by:
getWrappedInputStream
in interfaceInputStreamWrapper
- Returns:
- the underlying input stream wrapped by this class.
-