public class HttpMethodReleaseInputStream extends java.io.InputStream implements InputStreamWrapper
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.
Constructor and Description |
---|
HttpMethodReleaseInputStream(org.apache.http.HttpResponse httpMethod)
Constructs an input stream based on an
HttpResponse object representing an HTTP connection. |
Modifier and Type | Method and Description |
---|---|
int |
available() |
void |
close()
Standard input stream close method, except it ensures that
releaseConnection() is called
before the input stream is closed. |
protected void |
finalize()
Tries to ensure a connection is always cleaned-up correctly by calling
releaseConnection()
on class destruction if the cleanup hasn't already been done. |
org.apache.http.HttpResponse |
getHttpResponse()
Returns the underlying HttpResponse object.
|
java.io.InputStream |
getWrappedInputStream() |
int |
read()
Standard input stream read method, except it calls
releaseConnection() when the underlying
input stream is consumed. |
int |
read(byte[] b,
int off,
int len)
Standard input stream read method, except it calls
releaseConnection() when the underlying
input stream is consumed. |
protected void |
releaseConnection()
Forces the release of an HttpMethod's connection in a way that will perform all the necessary
cleanup through the correct use of HttpClient methods.
|
public HttpMethodReleaseInputStream(org.apache.http.HttpResponse httpMethod)
HttpResponse
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.httpMethod
- public org.apache.http.HttpResponse getHttpResponse()
protected void releaseConnection() throws java.io.IOException
java.io.IOException
public int read() throws java.io.IOException
releaseConnection()
when the underlying
input stream is consumed.read
in class java.io.InputStream
java.io.IOException
public int read(byte[] b, int off, int len) throws java.io.IOException
releaseConnection()
when the underlying
input stream is consumed.read
in class java.io.InputStream
java.io.IOException
public int available() throws java.io.IOException
available
in class java.io.InputStream
java.io.IOException
public void close() throws java.io.IOException
releaseConnection()
is called
before the input stream is closed.close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.InputStream
java.io.IOException
protected void finalize() throws java.lang.Throwable
releaseConnection()
on class destruction if the cleanup hasn't already been done.
This desperate cleanup act will only be necessary if the user of this class does not completely consume or close this input stream prior to object destruction. This method will log Warning messages if a forced cleanup is required, hopefully reminding the user to close their streams properly.
finalize
in class java.lang.Object
java.lang.Throwable
public java.io.InputStream getWrappedInputStream()
getWrappedInputStream
in interface InputStreamWrapper