You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by kk...@apache.org on 2011/11/11 03:19:32 UTC

svn commit: r1200696 - /tomcat/trunk/java/org/apache/coyote/http11/filters/FlushableGZIPOutputStream.java

Author: kkolinko
Date: Fri Nov 11 02:19:31 2011
New Revision: 1200696

URL: http://svn.apache.org/viewvc?rev=1200696&view=rev
Log:
Fix bug in FlushableGZIPOutputStream:
- It could not flush the last byte, because it should have been done in finish().
Note that GzipOutputFilter.end() calls finish() explicitly before calling close().
The tests called close() only and it did not catch this use case.
- Improve IOException handling in flushLastByte(), finish(), close().

Modified:
    tomcat/trunk/java/org/apache/coyote/http11/filters/FlushableGZIPOutputStream.java

Modified: tomcat/trunk/java/org/apache/coyote/http11/filters/FlushableGZIPOutputStream.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/coyote/http11/filters/FlushableGZIPOutputStream.java?rev=1200696&r1=1200695&r2=1200696&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/coyote/http11/filters/FlushableGZIPOutputStream.java (original)
+++ tomcat/trunk/java/org/apache/coyote/http11/filters/FlushableGZIPOutputStream.java Fri Nov 11 02:19:31 2011
@@ -66,8 +66,26 @@ public class FlushableGZIPOutputStream e
     }
 
     @Override
+    public synchronized void finish() throws IOException {
+        try {
+            flushLastByte();
+        } catch (IOException ignore) {
+            // If our write failed, then trailer write in finish() will fail
+            // with IOException as well, but it will leave Deflater in more
+            // consistent state.
+        }
+        super.finish();
+    }
+
+    @Override
     public synchronized void close() throws IOException {
-        flushLastByte();
+        try {
+            flushLastByte();
+        } catch (IOException ignored) {
+            // Ignore. As OutputStream#close() says, the contract of close()
+            // is to close the stream. It does not matter much if the
+            // stream is not writable any more.
+        }
         super.close();
     }
 
@@ -78,8 +96,9 @@ public class FlushableGZIPOutputStream e
 
     private void flushLastByte() throws IOException {
         if (hasLastByte) {
-            super.write(lastByte, 0, 1);
+            // Clear the flag first, because write() may fail
             hasLastByte = false;
+            super.write(lastByte, 0, 1);
         }
     }
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org