InputStream obtained from HttpMethod.getResponseBodyAsStream() could not be
closed before the end of the stream
---------------------------------------------------------------------------------------------------------------
Key: HTTPCLIENT-681
URL: https://issues.apache.org/jira/browse/HTTPCLIENT-681
Project: HttpComponents HttpClient
Issue Type: Bug
Affects Versions: 3.0.1
Environment: FreeBSD-6.2-STABLE, diable-jdk15
Reporter: Mario Pavlov
Hi Apache,
When I get an InputStream and try to close it before reading it to the end it
simply does not get closed...
here is a code example:
=========================================================================================
import java.io.IOException;
import java.io.InputStream;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.methods.GetMethod;
public class InputStreamCloseBug {
public static void main(String[] args) {
InputStream inputStream = null;
HttpClient httpClient = new HttpClient();
GetMethod getMethod = new
GetMethod("http://dlc.sun.com/netbeans/download/5_5_1/fcs/200704122300/netbeans-5_5_1.tar.gz");
try {
httpClient.executeMethod(getMethod);
inputStream = getMethod.getResponseBodyAsStream();
for(int i = 0; i < 10; i++) {
inputStream.read();
}
inputStream.close(); // same if I use getMethod.releaseConnection()
System.out.println("are we done yet ?"); // yeah, we are done after
a few minutes - depending on the connection
} catch (IOException ex) {
ex.printStackTrace();
}
}
}
=========================================================================================
it takes as long as the stream is read to its end
for me is about 6-8 minutes
I've tried also the following
=========================================================================================
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
public class InputStreamClose {
public static void main(String[] args) {
URL url;
try {
url = new
URL("http://dlc.sun.com/netbeans/download/5_5_1/fcs/200704122300/netbeans-5_5_1.tar.gz");
InputStream input = url.openStream();
for(int i = 0; i < 10; i++){
input.read();
}
input.close();
System.out.println("are we done yet!");
} catch (MalformedURLException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
=========================================================================================
which works as expected
it takes about 1 second
I believe that this is a critical bug
I haven't tried version 3.1RC1
I hope this helps
Happy bugfixing :)
Regards
MGP
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]