Author: kkolinko Date: Wed Aug 29 00:46:20 2012 New Revision: 1378403 URL: http://svn.apache.org/viewvc?rev=1378403&view=rev Log: Fix https://issues.apache.org/bugzilla/show_bug.cgi?id=53725
Another attempt to fixing BZ 53725. Do not restore compression level until the next write. Modified: tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/filters/FlushableGZIPOutputStream.java Modified: tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/filters/FlushableGZIPOutputStream.java URL: http://svn.apache.org/viewvc/tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/filters/FlushableGZIPOutputStream.java?rev=1378403&r1=1378402&r2=1378403&view=diff ============================================================================== --- tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/filters/FlushableGZIPOutputStream.java (original) +++ tomcat/tc7.0.x/trunk/java/org/apache/coyote/http11/filters/FlushableGZIPOutputStream.java Wed Aug 29 00:46:20 2012 @@ -42,6 +42,12 @@ public class FlushableGZIPOutputStream e private byte[] lastByte = new byte[1]; private boolean hasLastByte = false; + /** + * Flag that compression has to be re-enabled before the next write + * operation. + */ + private boolean flagReenableCompression = false; + @Override public void write(byte[] bytes) throws IOException { write(bytes, 0, bytes.length); @@ -53,6 +59,7 @@ public class FlushableGZIPOutputStream e if (length > 0) { flushLastByte(); if (length > 1) { + reenableCompression(); super.write(bytes, offset, length - 1); } rememberLastByte(bytes[offset + length - 1]); @@ -89,6 +96,13 @@ public class FlushableGZIPOutputStream e super.close(); } + private void reenableCompression() { + if (flagReenableCompression) { + flagReenableCompression = false; + def.setLevel(Deflater.DEFAULT_COMPRESSION); + } + } + private void rememberLastByte(byte b) { lastByte[0] = b; hasLastByte = true; @@ -96,6 +110,7 @@ public class FlushableGZIPOutputStream e private void flushLastByte() throws IOException { if (hasLastByte) { + reenableCompression(); // Clear the flag first, because write() may fail hasLastByte = false; super.write(lastByte, 0, 1); @@ -118,7 +133,7 @@ public class FlushableGZIPOutputStream e if (!def.finished()) { def.setLevel(Deflater.NO_COMPRESSION); flushLastByte(); - def.setLevel(Deflater.DEFAULT_COMPRESSION); + flagReenableCompression = true; } } out.flush(); @@ -139,5 +154,4 @@ public class FlushableGZIPOutputStream e } } while (len != 0); } - } --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org