Author: kkolinko Date: Mon Nov 7 02:16:17 2011 New Revision: 1198602 URL: http://svn.apache.org/viewvc?rev=1198602&view=rev Log: Add test for FlushableGZIPOutputStream.write(int). Remove unneeded &0xff in int->byte conversion from the method. According to JLS 3rd ed ch.5.1.3, narrowing of int to byte "simply discards all but the n lowest order bits".
Modified: tomcat/trunk/java/org/apache/coyote/http11/filters/FlushableGZIPOutputStream.java tomcat/trunk/test/org/apache/coyote/http11/filters/TestFlushableGZIPOutputStream.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=1198602&r1=1198601&r2=1198602&view=diff ============================================================================== --- tomcat/trunk/java/org/apache/coyote/http11/filters/FlushableGZIPOutputStream.java (original) +++ tomcat/trunk/java/org/apache/coyote/http11/filters/FlushableGZIPOutputStream.java Mon Nov 7 02:16:17 2011 @@ -62,7 +62,7 @@ public class FlushableGZIPOutputStream e @Override public synchronized void write(int i) throws IOException { flushLastByte(); - rememberLastByte((byte) (i & 0xFF)); + rememberLastByte((byte) i); } @Override Modified: tomcat/trunk/test/org/apache/coyote/http11/filters/TestFlushableGZIPOutputStream.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/coyote/http11/filters/TestFlushableGZIPOutputStream.java?rev=1198602&r1=1198601&r2=1198602&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/coyote/http11/filters/TestFlushableGZIPOutputStream.java (original) +++ tomcat/trunk/test/org/apache/coyote/http11/filters/TestFlushableGZIPOutputStream.java Mon Nov 7 02:16:17 2011 @@ -89,6 +89,48 @@ public class TestFlushableGZIPOutputStre } /** + * Test for {@code write(int)}. + */ + @Test + public void testWriteChar() throws Exception { + String phrase = "Apache Tomcat " + + "\u0410\u043f\u0430\u0447\u0435 \u0422\u043e\u043c\u043a\u0430\u0442 "; + byte[] data = phrase.getBytes("UTF-8"); + + ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream(); + OutputStream output = new FlushableGZIPOutputStream(byteOutStream); + + output.write(data); + for (int i=0; i<data.length; i++) { + output.write(data[i]); + } + output.flush(); + for (int i=0; i<data.length; i++) { + output.write(data[i]); + } + output.write(data); + output.close(); + + ByteArrayInputStream byteInStream = + new ByteArrayInputStream(byteOutStream.toByteArray()); + + GZIPInputStream inflaterStream = new GZIPInputStream(byteInStream); + ByteArrayOutputStream sink = new ByteArrayOutputStream(); + try { + IOTools.flow(inflaterStream, sink); + } finally { + sink.close(); + } + + byte[] decompressedBytes = sink.toByteArray(); + assertEquals(data.length * 4, decompressedBytes.length); + for (int i = 0; i < 4; i++) { + assertArrayEquals(data, Arrays.copyOfRange(decompressedBytes, + data.length * i, data.length * (i + 1))); + } + } + + /** * Loads file into memory. */ private byte[] loadFile(File file) throws IOException { --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org