Re: servlet problem with file transfer

I assume di.filesize and sentsize agree.
The problem may be in your client not the server.
I would guess that content-type may be text and that some
text conversion is going on.

I once tried progammatically

res.setContentType("text/html; charset=utf-8");
but the charset was ignored and stripped by Jigsaw.
(utf-8 is variable length code and does change text sizes).

Roland Mainz wrote:

> Hi !
>
> ----
>
> The following code should copy a file on disk to the requesting client,
> but the downloaded
> file differs in size and content from the original file.
> Any hint whats going wrong here ?
>
> -- snip --
>     private void putFile( DownloadItem di, HttpServletResponse res )
> throws IOException
>     {
>         d( "sending '" + di.filename + "' (" + di.contenttype + ")" );
>
>         // get source
>         FileInputStream in = new FileInputStream( di.filename );
>
>         // prepare and get destination
>         res.setContentType(   di.contenttype   );
>         res.setContentLength( (int)di.filesize ); /* seems that here
> sits a possible problem for files >= 2 GB... */
>         OutputStream out = res.getOutputStream();
>
>         int  readlen,
>              sentsize = 0;
>         byte buffer[] = new byte[ 256 ];
>
>         // loop until EOF
>         while( (readlen = in.read( buffer )) != -1 )
>         {
>           // throws IOException: broken pipe when download is canceled.
>           out.write( buffer, 0, readlen );
>           sentsize += readlen;
>         }
>
>         // Success ! Close streams.
>         out.close();
>         in.close();
>
>         d( "transfer of " + di.filename + " (" + di.filesize + "/" +
> sentsize + ") done." );
>     }
> -- snip --
>
> ----
>
> Bye,
> Roland
>
> --
>   __ .  . __
>  (o.\ \/ /.o)  Roland Mainz                               C programmer
>   \__\/\/__/   Roland.Mainz@informatik.med.uni-giessen.de MPEG specialist
>   /O /==\ O\   gisburn@w-specht.rhein-ruhr.de             Sun&&Amiga programmer
>  (;O/ \/ \O;)  TEL +49 (0) 2426901568  FAX +49 (0) 2426901569



--
Chris Turner, http://www.cycom.co.uk/

Received on Thursday, 1 April 1999 12:21:51 UTC