hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Siddharth Godbole" <siddharth.m.godb...@iiitb.ac.in>
Subject Re: Getting Images from the http server
Date Mon, 17 Jul 2006 13:17:51 GMT
Hi Julius,

   Thaks for your advice. That things works very well.

Regards,
Sid
----- Original Message ----- 
From: "Julius Davies" <juliusdavies@cucbc.com>
To: "HttpClient User Discussion" <httpclient-user@jakarta.apache.org>; 
"HttpClient List" <httpclient-user@jakarta.apache.org>
Sent: Monday, July 17, 2006 2:15 AM
Subject: RE: Getting Images from the http server


***********************
Your mail has been scanned by InterScan VirusWall.
***********-***********


Hi, Siddharth,

I think the cast to (char) is probably corrupting your image download. 
Images are binaries, so it's best to treat them as bytes and not chars.

I recommend using the (usually) higher performing read( byte[] ) and 
write( byte[] ) methods of InputStream and OutputStream.


FileOutputStream out = null;
try
{
  out = new FileOutputStream( "/downloads/image.jpg" );
  byte[] buf = new byte[ 4096 ];
  int r = in.read( buf );
  while ( r >= 0 )
  {
    if ( r > 0 )
    {
      out.write( buf, 0, r );
    }
    r = in.read( buf );
  }
}
finally
{
  try { if ( out != null ) out.close(); } catch ( IOException ioe ) {}
}





yours,

Julius


-----Original Message-----
From: Siddharth Godbole [mailto:siddharth.m.godbole@iiitb.ac.in]
Sent: Sun 7/16/2006 9:52 AM
To: HttpClient List
Cc:
Subject: Getting Images from the http server

Hi,

   I wanted to know about how i can get images from the server. Right now 
the method i used was like this:

1. Create a GET method for the image and Execute it.
2. Get its input stream
3. Use while loop as follows:
while((web_data = in.read()) != -1) {
      dataFile.writeOneChar((char)web_data);
      }
4. And then close the file and the connection.

But this is not working. Please can anyone tell me how can i achieve this ?

Regards,
Sid



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




-- 
No virus found in this incoming message.
Checked by AVG Free Edition.
Version: 7.1.394 / Virus Database: 268.10.1/389 - Release Date: 7/14/2006



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


Mime
View raw message