Hi,

I used a servlet to protect my html and image files. I
need to read this files and send them to the response
flow.
It's working, but when the file is too long (for
example, in the case of some JPEG or GIF files), a
byte seems to be

bad and corrupts the result.
Does anyone have the same problem and how to solve it?

regards,

Sylvain MARGA


ps: The code of the method is:

 public void returnFile(String filename,
ServletOutputStream out) throws FileNotFoundException,
IOException {

        // A FileInputStream is for bytes
        FileInputStream fis = null;
        int i=0;

        try {
          fis = new FileInputStream(filename);
          byte[] buf = new byte[4*1024];  // 4K buffer
          int bytesRead;

          while ((bytesRead = fis.read(buf)) != -1 ){
                out.write(buf, 0, bytesRead);
          }
        }
        catch(Exception e) {
                System.out.println("file error:"+e);
          }
        finally {
          if (fis != null) fis.close();
        }
  }

and I call it with:

ServletOutputStream out = response.getOutputStream();
response.setContentType(
getServletContext().getMimeType(request.getPathTranslated())
 );
returnFile( request.getPathTranslated() , out );

___________________________________________________________
Do You Yahoo!?
Votre e-mail @yahoo.fr gratuit sur http://courrier.yahoo.fr

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to