public class HttpMethodReleaseInputStream extends InputStream
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 the input stream. Additionally, this class attempts to release the connection and close the stream in this object's finalizer method, as a last resort to avoid leaking resources.
Important! This input stream must be completely consumed or closed to ensure the necessary cleanup operations can be performed.
构造器和说明 |
---|
HttpMethodReleaseInputStream(org.apache.http.HttpEntityEnclosingRequest httpMethod)
Constructs an input stream based on an
HttpMethod object
representing an HTTP connection. |
限定符和类型 | 方法和说明 |
---|---|
int |
available()
Standard input stream available method, except it ensures that
releaseConnection() is called if any errors are encountered from
the wrapped stream. |
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.HttpEntityEnclosingRequest |
getHttpRequest()
Returns the underlying HttpMethod object that contains/manages the actual
HTTP connection.
|
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.
|
mark, markSupported, read, reset, skip
public HttpMethodReleaseInputStream(org.apache.http.HttpEntityEnclosingRequest httpMethod)
HttpMethod
object
representing an HTTP connection. If a connection input stream is
available, this constructor wraps the underlying input stream and makes
that stream available. If no underlying connection is available, an empty
ByteArrayInputStream
is made available.httpMethod
- The HTTP method being executed, whose response content is to
be wrapped.public org.apache.http.HttpEntityEnclosingRequest getHttpRequest()
protected void releaseConnection() throws IOException
IOException
public int read() throws IOException
releaseConnection()
when the underlying input stream is consumed.read
在类中 InputStream
IOException
InputStream.read()
public int read(byte[] b, int off, int len) throws IOException
releaseConnection()
when the underlying input stream is consumed.read
在类中 InputStream
IOException
InputStream.read(byte[], int, int)
public int available() throws IOException
releaseConnection()
is called if any errors are encountered from
the wrapped stream.available
在类中 InputStream
IOException
InputStream.available()
public void close() throws IOException
releaseConnection()
is called before the input stream is closed.close
在接口中 Closeable
close
在接口中 AutoCloseable
close
在类中 InputStream
IOException
InputStream.close()
protected void finalize() throws 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.
Copyright © 2016. All rights reserved.