tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Prabhakar, Achal" <APrabha...@Central.UH.EDU>
Subject RE: Show files on filesystem
Date Wed, 16 Apr 2003 15:55:32 GMT
If you provide a download link, tomcat would have to do the same as you are
doing in your servlet. So provided you are buffering it properly it is the
same as tomcat handling the download.


-----Original Message-----
From: harm@informatiefabriek.nl [mailto:harm@informatiefabriek.nl]
Sent: Wednesday, April 16, 2003 8:59 AM
To: Tomcat Users List
Subject: Re: Show files on filesystem


Thanks, that's a big help!

Still I'm wondering. Would it not be more efficient to just provide a 
direct download link?

Thanks,

Harm.




Tim Funk <funkman@joedog.org> 
04/16/2003 03:52 PM
Please respond to
"Tomcat Users List" <tomcat-user@jakarta.apache.org>


To
Tomcat Users List <tomcat-user@jakarta.apache.org>
cc

Subject
Re: Show files on filesystem






Actually that was a little inefficientbut was OK. You are not streaming 
the 
file as it is read. For efficiency, use a byte buffer to reduce the number 
of 
function calls.

  File f = new File(valueObj.getPath());
  InputStream is = new BufferedInputStream(new
  FileInputStream(valueObj.getPath()));
  OutputStream os = response.getOutputStream();
  response.setContentType("application/pdf");

  byte[] buffer = new byte[1024]; /*or whatever size*/

  int read = is.read(buffer);
  while (read >=0 ) {
     if (read>0)
         os.write(buffer,0, read);
     read = is.read(buffer);
  }

/* NOT NEEDED  os.flush(); */
  is.close();
  os.close();

-Tim

harm@informatiefabriek.nl wrote:
> Hehe ;-)
> 
> I know how java IO works... 
> I have coded the following:
> 
> -----------------------
> File f = new File(valueObj.getPath());
> InputStream is = new BufferedInputStream(new 
> FileInputStream(valueObj.getPath()));
> OutputStream os = response.getOutputStream();
> response.setContentType("application/pdf");
> int b;
> while ((b = is.read()) != -1) {
>         os.write(b);
> }
> os.flush();
> os.close();
> is.close(); 
> ----------------------------
> 
> I'm just wondering if this method is efficient. Because the file first 
has 
> to be read completely and then written to the output stream.
> 
> Thanks,
> 
> Harm.
> 


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




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

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


Mime
View raw message