hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Antonio Xu <Antonio...@Sun.COM>
Subject out out memory problem of Httpclient
Date Thu, 03 Feb 2005 05:28:55 GMT
Hello All,

This is Antonio Xu, I'm writing a http application base on HttpClient 
2.02, but today, I found there is serious problem (out of memory) of 
httpclient, that make my http application keep on crash. In my code, I 
use httpclient's get method to download a file (more than 2MB) form my 
apache web server, but every time, when I try to get the stream of 
response, httpclient will throw a out of memory exception, that make my 
application crash. Please see my codes below:

       String res;
       GetMethod method = null;
       try {
           method = new GetMethod(path);
       } catch (IllegalArgumentException e) {
           throw new HttpException("Wrong fetch Url");
       }
       method.setDoAuthentication(true);
       try {
           executeMethod(method);

           InputStream is = method.getResponseBodyAsStream();  // if the 
download file more than 2MB, before the stream will be returned, the 
httpclient throw a out of memory exception.
           is.read(buf, 0, 20480-1);
           res = new String(buf);
           is.close();
       }catch(IOException e){
           return null;
       }
       finally {
           method.releaseConnection();
       }

I wonder who can help me resolve my problem, if this issue cannot be 
resolved, I have to give up to use HttpClient.

Thanks,
Anto



---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org


Mime
View raw message