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:[EMAIL PROTECTED] 
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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to