• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Corrupt PDF Files

 
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay. So all is good and my PDF files are streaming great. Funny thing is, some of the files are coming back as currupt. When I hit them directly using just a path, they are not corrupt. Does anyone have any ideas to what might cause this?
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you using Reader or Writer rather than InputStream or OutputStream?
Are you using String or char[] rather than byte[]?
Are you ever converting between byte and String or char?
Are you using a mime-type that represents text (so that maybe your browser is doing one of the above)?
[ August 29, 2002: Message edited by: Dave Landers ]
 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for your quick reply. To answer your questions...
Q1) Are you using Reader or Writer rather than InputStream or OutputStream?
A1) I'm using a FileInputStream
Q2) Are you using String or char[] rather than byte[]?
A2) I am using byte to read in the data
Q3) Are you ever converting between byte and String or char?
No.
Q4) Are you using a mime-type that represents text (so that maybe your browser is doing one of the above)?
A4) Yes.
Keep this in mind. This streamer does work with many of the PDF files. But it doesn't work with all of them.
Here is my code.. see what you think...
 
Dave Landers
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
At first glance, that looks OK to me.
Other things I'd probably check...
Try with other browsers - what I'm thinking here is I have seen IE ignore content type in favor of the file extension ".pdf" on the end of the URL. annoying.
Make sure the rest of your servlet program is not writing things to the output stream that may disrupt the output (setting headers or whatever).
Write a java program to connect to that servlet and dump the retrieved stream back to a file - then you can compare the files and see where the problem is - is it truncated or is is the data changing or what else. Might give you a clue what to look for.
Good luck - chances are when you are done you will either cry "Doh!" or you will have learned something really useful.
 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good idea about writing the file back out and comparing. Will do.
-Dale
 
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The BufferedOutputStream seems a bit redundant (you do some buffering yourself), but does it help if you flush() it?
 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Okay, so here's the deal. It seems that the file is being truncated. Streaming the file back to another file to do a compare worked great! Terrific idea! I'm about 389 bytes short. It seems those last bytes are being lost. Any ideas in how to avoid this?
 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by David Weitzman:
The BufferedOutputStream seems a bit redundant (you do some buffering yourself), but does it help if you flush() it?


Hmm.. yeah. I think you're right. It might be redundant. Which method might be more useful to keep?
Dale
 
David Weitzman
Ranch Hand
Posts: 1365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would just write strait to outStream. And did you try flush()ing?
 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by David Weitzman:
I would just write strait to outStream. And did you try flush()ing?


Thanks.. Flushing out the buffer did the trick. Thanks so much!
Dale
 
Ranch Hand
Posts: 1056
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Glad that worked, but I'm wondering why the buffer didn't flush automatically when it was closed (or when it was finalized).
 
Dave Landers
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The servlet container would have flushed the response.getOutputStream() stream probably just by closing it). But it would not know about leftover bytes sitting in the BufferedOutputStream that wrapped it. Those are the ones that got lost.
Flushing that buffer gets those bytes to the response stream where the servlet container can flush them to the client.
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Threads like this make me so proud to be a participant in JavaRanch!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I think you can try a utility called Advanced PDF Repair to repair your PDF file. It works rather well for my corrupt PDF files. Its web address is http://www.datanumen.com/apdfr/
 
reply
    Bookmark Topic Watch Topic
  • New Topic