Unidata/thredds — pull request #13 by tkunicki-usgs (2012-08-05 02:50:55+00:00)
Title: Added ConsumeOnCloseInputStream to wrap returned InputStream instance returned from httpclient API

This is one step towards cleaning up HTTPMethod InputStream resources for reuse by the HTTP Connection pool. One thing that may be added is calling the HTTPMethod.releaseConnection on the InputStream.close() of the InputStream instance returned from HTTPMethod. As an example once the overridden InputStream.close() is called the HTTPMethod instance should be immediately cleaned up instead of requiring explicit calls to HTTPMethod.close(). This could be done in the ConsumeOnCloseInputConnection.close() method by calling method.releaseConnection(). From investigating the code base, the are numerous uses of InputStream instances returned from HTTPMethod.getResponseBodyAsStream() or getResponseAsStream() where the HTTPMethod instance goes out of scope and close() can never be called (in particular with CdmRemote, as well as other calls the pass up the InputStream instance returned from HTTPMethod). Tying the method.releaseConnection() to the InputStream.close() would allow these execution flows to clean up the underlying HTTPMethod instance simply by calling close() on the returned InputStream instance..