tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Tim Funk <funk...@joedog.org>
Subject Re: Show files on filesystem
Date Wed, 16 Apr 2003 14:04:09 GMT
That would be too easy :)

-Tim

harm@informatiefabriek.nl wrote:
> 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