tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Wade Chandler" <wchand...@redesetgrow.com>
Subject RE: File writing performance
Date Tue, 21 Oct 2003 19:21:00 GMT
The main problem with performance comes from your source code.  You are
reading 1 byte at a time then writing 1 byte at a time.  Use a buffered
input stream, and also use a buffered output stream.  Then read and
write a good number of bytes.  Maybe use a static section so you can
change the number of bytes for the buffers with a  properties file.

Wade

-----Original Message-----
From: Carlos Pereira [mailto:khepera@portugalmail.pt] 
Sent: Tuesday, October 21, 2003 3:10 PM
To: Tomcat Users List
Subject: File writing performance


I want to make a servlet which catches all accesses to *.swf files (with
a mapping) and only retrieves them if the permissions for the user allow
it. That can be done simply with:

<code>
// check user permissions and redirect to error page if needed // else:
response.setContentType("application/x-shockwave-flash");
DataInputStream dis = new DataInputStream(
  getServletContext().getResourceAsStream(filename)
);
OutputStream out = response.getOutputStream();
int b = -1;
while((b = dis.read()) != -1) {
  out.write(b);
}
out.close();
</code>

My question: is this approach more expensive than simply retrieving the
file? If so, is it significative?

Best regards,
Carlos Pereira

---------------------------------------------------------------------
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