Daniel Blumenthal wrote:
Hi there, and happy holidays!
I have an application in which there are certain files which are only
accessible by certain users.  So, when a request comes to my "GetFile"
Action, I first verify that they have the correct permissions, then send the
file by opening the file and reading it into the response output stream
(code included below).  This works, but seems unbelievably hacky, and I was
wondering if there were a better way to do this.

Thanks!

Daniel

the code:
response.reset();
   response.setContentType(mimeType);

File f = new File(path); long filelen = f.length();
   response.setContentLength((int)filelen);
FileInputStream fileIn = new FileInputStream(f);
   BufferedInputStream bufIn = new BufferedInputStream(fileIn);
   BufferedOutputStream out = new
BufferedOutputStream(response.getOutputStream());
final int READ_SIZE = 1024;
   int count;
   byte[] buffer = new byte[READ_SIZE];
   while ((count = bufIn.read(buffer,0,READ_SIZE)) != -1)
     out.write(buffer,0,count);
out.flush();
   out.close();
response.flushBuffer();

What you have looks pretty standard. Make sure your action returns null so Struts knows the response is complete, and you should be fine.

L.


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

Reply via email to