changeset 801:72662bb585ba stream

remove all ServletOutputStream.flush(). (stupid me ;-)
author robcast
date Sat, 19 Feb 2011 11:07:08 +0100
parents 65e70c03870b
children 034ab33984d2
files servlet/src/digilib/image/ImageLoaderDocuImage.java servlet/src/digilib/pdf/PDFFileWorker.java servlet/src/digilib/pdf/PDFStreamWorker.java servlet/src/digilib/servlet/DocumentBean.java servlet/src/digilib/servlet/Scaler.java servlet/src/digilib/servlet/ServletOps.java
diffstat 6 files changed, 33 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/servlet/src/digilib/image/ImageLoaderDocuImage.java	Sat Feb 19 09:56:18 2011 +0100
+++ b/servlet/src/digilib/image/ImageLoaderDocuImage.java	Sat Feb 19 11:07:08 2011 +0100
@@ -305,12 +305,8 @@
 		} catch (IOException e) {
 		    logger.error("Error writing image:", e);
 			throw new ServletException("Error writing image:", e);
-		} finally {
-			// clean up
-			if (writer != null) {
-				writer.dispose();
-			}
 		}
+		// TODO: should we: finally { writer.dispose(); }
 	}
 
 	public void scale(double scale, double scaleY) throws ImageOpException {
--- a/servlet/src/digilib/pdf/PDFFileWorker.java	Sat Feb 19 09:56:18 2011 +0100
+++ b/servlet/src/digilib/pdf/PDFFileWorker.java	Sat Feb 19 11:07:08 2011 +0100
@@ -46,10 +46,18 @@
     }
     
     public File call() throws Exception {
-    	OutputStream outstream = streamWorker.call();
-    	outstream.flush();
-    	// move temporary to final file
-    	tempFile.renameTo(finalFile);
+        OutputStream outstream = null;
+        try {
+            outstream = streamWorker.call();
+            outstream.flush();
+            outstream.close();
+            // move temporary to final file
+            tempFile.renameTo(finalFile);
+        } finally {
+            if (outstream != null) {
+                outstream.close();
+            }
+        }
         return finalFile;
     }
     
--- a/servlet/src/digilib/pdf/PDFStreamWorker.java	Sat Feb 19 09:56:18 2011 +0100
+++ b/servlet/src/digilib/pdf/PDFStreamWorker.java	Sat Feb 19 11:07:08 2011 +0100
@@ -97,6 +97,7 @@
 		doc.close();
 		logger.debug("PDF: " + outstream + " doc.close() ("
 				+ (System.currentTimeMillis() - start_time) + "ms)");
+		docwriter.flush();
 		docwriter.close();
 		return outstream;
 	}
--- a/servlet/src/digilib/servlet/DocumentBean.java	Sat Feb 19 09:56:18 2011 +0100
+++ b/servlet/src/digilib/servlet/DocumentBean.java	Sat Feb 19 11:07:08 2011 +0100
@@ -35,7 +35,6 @@
 import digilib.auth.AuthOps;
 import digilib.io.DocuDirCache;
 import digilib.io.DocuDirectory;
-import digilib.io.ImageFile;
 import digilib.io.FileOps.FileClass;
 import digilib.io.ImageInput;
 import digilib.io.ImageSet;
--- a/servlet/src/digilib/servlet/Scaler.java	Sat Feb 19 09:56:18 2011 +0100
+++ b/servlet/src/digilib/servlet/Scaler.java	Sat Feb 19 11:07:08 2011 +0100
@@ -23,8 +23,6 @@
 import digilib.image.ImageWorker;
 import digilib.io.DocuDirCache;
 import digilib.io.DocuDirectory;
-import digilib.io.DocuDirent;
-import digilib.io.FileOps.FileClass;
 import digilib.io.ImageInput;
 import digilib.util.DigilibJobCenter;
 
@@ -32,7 +30,7 @@
 public class Scaler extends HttpServlet {
 
     /** digilib servlet version (for all components) */
-    public static final String version = "1.9.0a";
+    public static final String version = "1.9.0a2";
 
     /** servlet error codes */
     public static enum Error {UNKNOWN, AUTH, FILE, IMAGE};
@@ -311,6 +309,11 @@
                 img = this.errorImgFile;
                 status = HttpServletResponse.SC_BAD_REQUEST;
             }
+            if (response.isCommitted()) {
+                // response already committed
+                logger.error("Unable to send error: " + msg);
+                return;
+            }
             if (type == ErrMsg.TEXT) {
                 ServletOps.htmlMessage(msg, response);
             } else if (type == ErrMsg.CODE) {
--- a/servlet/src/digilib/servlet/ServletOps.java	Sat Feb 19 09:56:18 2011 +0100
+++ b/servlet/src/digilib/servlet/ServletOps.java	Sat Feb 19 11:07:08 2011 +0100
@@ -238,22 +238,30 @@
             }
             response.addHeader("Content-Disposition", "attachment; filename=\""+name+"\"");
         }
+        FileInputStream inFile = null;
         try {
-            FileInputStream inFile = new FileInputStream(f);
+            inFile = new FileInputStream(f);
             OutputStream outStream = response.getOutputStream();
+            // TODO: should we set content length? 
+            // see http://www.prozesse-und-systeme.de/servletFlush.html
             response.setContentLength( (int) f.length());
             byte dataBuffer[] = new byte[4096];
             int len;
             while ((len = inFile.read(dataBuffer)) != -1) {
                 // copy out file
                 outStream.write(dataBuffer, 0, len);
-                outStream.flush();
             }
-            response.flushBuffer();
-            inFile.close();
         } catch (IOException e) {
             logger.error("Error sending file:", e);
             throw new ServletException("Error sending file:", e);
+        } finally {
+            try {
+                if (inFile != null) {
+                    inFile.close();
+                }
+            } catch (IOException e) {
+                // nothing to do
+            }
         }
     }
 
@@ -301,13 +309,11 @@
             // write the image
             response.setContentType(mimeType);
             img.writeImage(mimeType, outstream);
-            outstream.flush();
         } catch (IOException e) {
             logger.error("Error sending image:", e);
             throw new ServletException("Error sending image:", e);
-        } finally {
-            img.dispose();
         }
+        // TODO: should we: finally { img.dispose(); }
     }
 
 }
\ No newline at end of file