Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
    Bookmark Topic Watch Topic
  • New Topic

HELP! Slow response times while dispatching pdf files

 
Dale DeMott
Ranch Hand
Posts: 515
  • Mark post as helpful
  • send pies
  • Report post to moderator
I'm trying to dispatch some pdf files to my browser via a servlet to control who can get to it and who can't. Using a url with .pdf at the end works fast, but it also means everyone can get to them (even if I don't want everyone to get to them) Currently the PDF files are taking quite some time to dispatch. I'm using some file streaming as you can see below. Is there any technique or different classes I can use to speed this up? Maybe a Buffered File Reader??? What would help?

Here's my code...

[ August 06, 2002: Message edited by: Dale DeMott ]
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Report post to moderator
A Reader will be useless for a PDF file - it's not text data. A BufferedOutputStream would help - but more useful here would be to use the read(byte[]) and write(byte[]) methods to push bytes in bulk rather than one at a time:

You could try also wrapping the FileOutputStream with a BufferedOutputStream, but I doubt you'd see much further benefit since you've already got one buffer in the system. Experiment with the buffer size to see what works best for you - there's usually a large range in which the size makes little difference.
[ August 06, 2002: Message edited by: Jim Yingst ]
 
Dave Landers
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Report post to moderator
Seems to me you could put the pdf files in the webapp and add security-constraints in web.xml?
But if you need some kind of programatic security control in the servlet, use buffered streams.
 
Jim Yingst
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Report post to moderator
Sigh. Closing this thread since it's now a duplicate, and the I/O forum is more appropriate. Followup here.
 
    Bookmark Topic Watch Topic
  • New Topic