You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by Vijay Gomatam <vi...@gmail.com> on 2006/03/27 23:11:31 UTC
Hi ... httpclient for PDF files ???
Hi ..
I am using httpclient for a few hours ... I have just downloaded the jar
3.0over the weekend!
I tried to retrieve a remote pdf file, but the inputstream doesn't give me
the properly formatted original file!
Would httpclient support the pdfs? If so, is there anything I need to
configure further to see the original pdf ??
Thanks!
Vijay.
Re: Hi ... httpclient for PDF files ???
Posted by Ortwin Glück <od...@odi.ch>.
Vijay,
Sorry we can not help you without any logging output. A quick guess is,
that the server may use gzip/deflate compression, which is not handeled
automatically by HttpClient. You may have to run the stream through
GZIPInputStream or InflaterInputStream depending on the HTTP headers.
Cheers
Ortwin Glück
Vijay Gomatam wrote:
> 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.
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
Re: Hi ... httpclient for PDF files ???
Posted by Vijay Gomatam <vi...@gmail.com>.
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 <od...@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
>
>
Re: Hi ... httpclient for PDF files ???
Posted by Vijay Gomatam <vi...@gmail.com>.
Thanks Ortwin ... I shall try that.
-Vijay.
=====
On 3/28/06, Ortwin Glück <> 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
>
>
Re: Hi ... httpclient for PDF files ???
Posted by Ortwin Glück <od...@odi.ch>.
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
Re: Hi ... httpclient for PDF files ???
Posted by Vijay Gomatam <vi...@gmail.com>.
Hi Ortwin,
Thanks for the reply... I tried to get the InputStream and put it to a
fileoutputstream and look into the file! I see the new file which is a few
KB lesser than the original file !!
For a clearer pic , I am attaching a code snippet! Is this a right approach?
// -----
HttpClient httpClient=*new* HttpClient();
httpClient.setConnectionTimeout(_connectionCreateTimeout);
httpClient.setTimeout(_connectionReadTimeout);
postMethod=*new* PostMethod(url);
postMethod.setFollowRedirects(*false*);
httpClient.executeMethod(postMethod);
InputStream responseBodyStream = postMethod.getResponseBodyAsStream();
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);
}
data.close();
// -----
Thanks a ton ...
Regards,
Vijay.
On 3/28/06, Ortwin Glück <od...@odi.ch> wrote:
>
> Vijay,
>
> HttpClient is completely content agnostic. You can use it to transfer
> arbitrary data, including PDFs.
>
> Ortwin Glück
>
> Vijay Gomatam wrote:
> > Hi ..
> >
> > I am using httpclient for a few hours ... I have just downloaded the jar
> > 3.0over the weekend!
> >
> > I tried to retrieve a remote pdf file, but the inputstream doesn't give
> me
> > the properly formatted original file!
> >
> > Would httpclient support the pdfs? If so, is there anything I need to
> > configure further to see the original pdf ??
> >
> > Thanks!
> > Vijay.
> >
>
> --
> [web] http://www.odi.ch/
> [blog] http://www.odi.ch/weblog/
> [pgp] key 0x81CF3416
> finger print F2B1 B21F F056 D53E 5D79 A5AF 02BE 70F5 81CF 3416
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org
>
>
Re: Hi ... httpclient for PDF files ???
Posted by Ortwin Glück <od...@odi.ch>.
Vijay,
HttpClient is completely content agnostic. You can use it to transfer
arbitrary data, including PDFs.
Ortwin Glück
Vijay Gomatam wrote:
> Hi ..
>
> I am using httpclient for a few hours ... I have just downloaded the jar
> 3.0over the weekend!
>
> I tried to retrieve a remote pdf file, but the inputstream doesn't give me
> the properly formatted original file!
>
> Would httpclient support the pdfs? If so, is there anything I need to
> configure further to see the original pdf ??
>
> Thanks!
> Vijay.
>
--
[web] http://www.odi.ch/
[blog] http://www.odi.ch/weblog/
[pgp] key 0x81CF3416
finger print F2B1 B21F F056 D53E 5D79 A5AF 02BE 70F5 81CF 3416
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-dev-help@jakarta.apache.org