-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Rob,
*sigh* We'll argue about this all week if someone doesn't just reformat your code and go for it. Evidently, I've got nothing better to do. On 5/19/2011 6:44 AM, Rob GB wrote: > public void service(HttpServletRequest request, HttpServletResponse > response) > throws IOException { > byte buf[] = new byte[1024 * 4]; > try { > File file = new File(realFilename); > int size = (int) file.length(); Fail: file size truncation. > BufferedInputStream realFile = new BufferedInputStream(new > FileInputStream(file)); > OutputStream out = response.getOutputStream(); > response.setContentLength(size); Fail: file size truncation (it's a stupid oversight in the Servlet API that we have to live with, forever, now). You might also want to sent a Content-Type header. That's always nice. > while (true) { > int count = realFile.read(buf); > if (count == -1) { > break; > } > out.write(buf, 0, count); > } That's an odd way to write that loop. You know, it can be written without a "break" and in fewer lines? > out.flush(); > } catch (FileNotFoundException e) { > logger.error("Stream download failed, file not found: " > + realFilename, e); > response.sendError(404); > } catch (Exception e) { > logger.error("DownloadException:", e); What, no 500 error? > } > } > > However once in a while I get an error that prevents files from being > downloaded: > > DownloadException: java.net.SocketException: Broken pipe > at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:366) > [...] It's a broken pipe. Your client didn't wait for the download to complete before hanging up the phone. I don't believe this is a bug in your code. > <Connector port="8968" > disableUploadTimeout="true" > enableLookups="false" > acceptCount="10000" That's a pretty big accept queue. Why do you need it that big? > connectionTimeout="120000" That's a long time to wait around for an HTTP request line. Why do you need it to be so long? > maxKeepAliveRequests="20" > maxThreads="300" > threadPriority="java.lang.Thread#MAX_PRIORITY" Let me guess... your application wasn't going fast enough? Is there a reason why need all your request-processing threads to go at MAX_PRIORITY? > tcpNoDelay="true" This is the default. > protocol="org.apache.coyote.http11.Http11Protocol" > compression="on" > > compressableMimeType="text/html,text/xml,text/plain,text/css,text/javascript" > server="" > minSpareThreads="100" > maxSpareThreads="300" > strategy="ms" > clockless="false"/> I don't recognize those last four settings. For the (ignored) threading settings, maybe you intended to use an <Executor>? - -chris -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.10 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAk3VgyoACgkQ9CaO5/Lv0PARMACfTMaIH/cPRjuYYtcKJ7OigPgp gUIAnA9EX2LlQC6sMn7T/vtdmwOiOBe/ =LZMo -----END PGP SIGNATURE----- --------------------------------------------------------------------- To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org