public class HttpMethodReleaseInputStream
extends com.amazonaws.internal.SdkInputStream
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.
Constructor and Description |
---|
HttpMethodReleaseInputStream(org.apache.http.HttpEntityEnclosingRequest httpMethod)
Constructs an input stream based on an
HttpMethod object
representing an HTTP connection. |
Modifier and Type | Method and Description |
---|---|
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.
|
protected InputStream |
getWrappedInputStream()
Returns the underlying input stream, if any, from the subclass; or null
if there is no underlying input stream.
|
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.
|
abort, abortIfNeeded, isMetricActivated, release
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
in class InputStream
IOException
InputStream.read()
public int read(byte[] b, int off, int len) throws IOException
releaseConnection()
when the underlying input stream is consumed.read
in class 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
in class InputStream
IOException
InputStream.available()
public void close() throws IOException
releaseConnection()
is called before the input stream is closed.close
in interface Closeable
close
in interface AutoCloseable
close
in class 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.
protected InputStream getWrappedInputStream()
com.amazonaws.internal.SdkInputStream
getWrappedInputStream
in class com.amazonaws.internal.SdkInputStream
Copyright © 2015. All rights reserved.