- From: Roland Mainz <Roland.Mainz@informatik.med.uni-giessen.de>
- Date: Mon, 05 Apr 1999 19:11:44 +0200
- To: "jigsaw@w3.org" <jigsaw@w3.org>, W3 Jigsaw Mailinglist <www-jigsaw@w3.org>, Yves Lafon <ylafon@w3.org>, Benoit Mahe <Benoit.Mahe@sophia.inria.fr>
Hi ! ---- The following code does NOT work, and the question is: WHY ? The file downloaded by the browser is different in size from the original file,and ZIP files are not recogzized as such by WinZip 7.0 (reg). (Method d( String ) is only a logging function). di.filename ="dk-lite.zip"; di.contenttype = "application/octet-stream"; It doesn't matter if I use a BufferedINputStream instead of the plane FileInputStream as input, and it doesn't matter to move getOutputStream behind the setContentType method call... It doesn't matter to use the int-copy-loop below, or the 256-byte copy loop which is commented-out here. Hint to Yvves/Benoit: This may be a problem with charset-conversion, e.g. that application/octet-stream contents are converted by jigsaw's SetvletOutputStream in a case where no conversion should be done. Last but not least my code may be buggy - in this case - sorry. -- snip -- private void putFile( DownloadItem di, HttpServletResponse res ) throws IOException { d( "sending '" + di.filename + "' (" + di.contenttype + ")" ); // get source // InputStream in = new FileInputStream( di.filename ); InputStream in = new BufferedInputStream( new FileInputStream( di.filename ) ); OutputStream out = res.getOutputStream(); // prepare and get destination res.setContentType( di.contenttype ); res.setContentLength( (int)di.filesize ); /* seems that here sits a possible problem for files >= 2 GB... */ int i; while ((i = in.read()) != -1) { out.flush(); out.write( i ); } 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.flush(); out.write( buffer, 0, readlen ); sentsize += readlen; } // Success ! Close streams. */ out.flush(); out.close(); in.close(); d( "transfer of " + di.filename + " (" + di.filesize + "/" + sentsize + ") done." ); } } -- snip -- -- __ . . __ (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
Received on Monday, 5 April 1999 13:10:51 UTC