W3C home > Mailing lists > Public > www-jigsaw@w3.org > March to April 1999

Re: servlet problem with file transfer

From: Christopher William Turner <cwturner@cycom.co.uk>
Date: Thu, 1 Apr 1999 11:58:16 -0500 (EST)
Message-ID: <3703A422.2B02A188@cycom.co.uk>
To: Roland Mainz <Roland.Mainz@informatik.med.uni-giessen.de>
CC: W3 Jigsaw Mailinglist <www-jigsaw@w3.org>
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 GMT

This archive was generated by hypermail 2.2.0+W3C-0.50 : Monday, 9 April 2012 12:13:29 GMT