hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vijay Gomatam" <vijayraman.goma...@gmail.com>
Subject Re: Hi ... httpclient for PDF files ???
Date Wed, 29 Mar 2006 00:39:25 GMT
Ortwin ...

Thanks for the reply. I tried a lot on it, but was unsuccessful. So, I shall
go ahead and use the traditional openConnection() .....

Anyways! Attached is the error (as image file) fyi.

Thanks for your time.

Regards,
Vijay.

=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=


On 3/28/06, Ortwin Gl├╝ck <odi@odi.ch> wrote:
>
> Vijay,
>
> It's wrong to use a DataInputStream this way. DataInputStream is for
> serialized Java objects! A typical beginner's mistake I should put in my
> list of anti-patterns: http://www.odi.ch/prog/design/newbies.php
>
> The correct way to copy a byte stream to disk is:
>
> InputStream in = new BufferedInputStream(responseBodyStream);
> FileOutputStream fos = new FileOutputStream("rwservlet.pdf");
> byte[] buffer = new byte[4098];
> int len = 0;
> while ((len = in.read(buffer) > 0) {
>     fos.write(buffer, 0, len);
> }
>
> Cheers
>
> Ortwin
>
> Vijay Gomatam wrote:
> > DataInputStream data = new DataInputStream(new
> > BufferedInputStream(responseBodyStream));
> > FileOutputStream fos = new FileOutputStream("rwservlet.pdf");
> >
> > *while* ((c =data.read(b)) != -1){
> >
> > *byte*[] inter=*new* *byte*[c];
> >
> > *for*(*int* i=0;i<c;i++)  inter[i]=b[i];
> >
> > fos.write(inter);
> >
> > }
>
>
> ---------------------------------------------------------------------
> 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