Return-Path: X-Original-To: apmail-tomcat-dev-archive@www.apache.org Delivered-To: apmail-tomcat-dev-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id E04899CA9 for ; Sun, 6 Nov 2011 18:54:19 +0000 (UTC) Received: (qmail 22279 invoked by uid 500); 6 Nov 2011 18:54:19 -0000 Delivered-To: apmail-tomcat-dev-archive@tomcat.apache.org Received: (qmail 22193 invoked by uid 500); 6 Nov 2011 18:54:19 -0000 Mailing-List: contact dev-help@tomcat.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "Tomcat Developers List" Delivered-To: mailing list dev@tomcat.apache.org Received: (qmail 22184 invoked by uid 99); 6 Nov 2011 18:54:19 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 06 Nov 2011 18:54:19 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=5.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sun, 06 Nov 2011 18:54:15 +0000 Received: from eris.apache.org (localhost [127.0.0.1]) by eris.apache.org (Postfix) with ESMTP id F12DA23888E4 for ; Sun, 6 Nov 2011 18:53:53 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1198528 - /tomcat/trunk/test/org/apache/coyote/http11/filters/TestFlushableGZIPOutputStream.java Date: Sun, 06 Nov 2011 18:53:53 -0000 To: dev@tomcat.apache.org From: kkolinko@apache.org X-Mailer: svnmailer-1.0.8-patched Message-Id: <20111106185353.F12DA23888E4@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kkolinko Date: Sun Nov 6 18:53:53 2011 New Revision: 1198528 URL: http://svn.apache.org/viewvc?rev=1198528&view=rev Log: svn:eol-style=native Modified: tomcat/trunk/test/org/apache/coyote/http11/filters/TestFlushableGZIPOutputStream.java (contents, props changed) 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=1198528&r1=1198527&r2=1198528&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/coyote/http11/filters/TestFlushableGZIPOutputStream.java (original) +++ tomcat/trunk/test/org/apache/coyote/http11/filters/TestFlushableGZIPOutputStream.java Sun Nov 6 18:53:53 2011 @@ -1,119 +1,119 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.coyote.http11.filters; - -import java.io.ByteArrayInputStream; -import java.io.ByteArrayOutputStream; -import java.io.File; -import java.io.FileInputStream; -import java.io.IOException; -import java.io.OutputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.zip.GZIPInputStream; - -import static org.junit.Assert.assertArrayEquals; -import static org.junit.Assert.assertEquals; - -import org.junit.Test; - -import org.apache.catalina.util.IOTools; - -/** - * Reproduces what current appears to be a JVM bug. Note: This test case is not - * part of the Standard test suite that is execute by ant test. - */ -public class TestFlushableGZIPOutputStream { - - @Test - public void testBug52121() throws Exception { - - ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream(); - OutputStream output = new FlushableGZIPOutputStream(byteOutStream); - - File sourcesDir = new File("test/org/apache/coyote/http11/filters/"); - List parts = new ArrayList(); - byte[] part; - - part = loadFile(new File(sourcesDir, "bug52121-part1")); - parts.add(part); - flowBytes(part, output); - output.flush(); - - part = loadFile(new File(sourcesDir, "bug52121-part2")); - parts.add(part); - flowBytes(part, output); - output.flush(); - - part = "data2".getBytes("ASCII"); - parts.add(part); - output.write(part); - output.flush(); - - 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(); - int originalLength = 0; - for (byte[] bytes : parts) { - assertArrayEquals(bytes, Arrays.copyOfRange(decompressedBytes, - originalLength, originalLength + bytes.length)); - originalLength += bytes.length; - } - assertEquals(originalLength, decompressedBytes.length); - } - - /** - * Loads file into memory. - */ - private byte[] loadFile(File file) throws IOException { - ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream(); - FileInputStream input = new FileInputStream(file); - try { - IOTools.flow(input, byteOutStream); - } finally { - input.close(); - } - return byteOutStream.toByteArray(); - } - - /** - * Writes data to the stream and returns the size of the file. - */ - private void flowBytes(byte[] bytes, OutputStream output) - throws IOException { - // Could use output.write(), but IOTools writes in small portions, and - // that is more natural - ByteArrayInputStream byteInStream = new ByteArrayInputStream(bytes); - try { - IOTools.flow(byteInStream, output); - } finally { - byteInStream.close(); - } - } -} +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.coyote.http11.filters; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.IOException; +import java.io.OutputStream; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.zip.GZIPInputStream; + +import static org.junit.Assert.assertArrayEquals; +import static org.junit.Assert.assertEquals; + +import org.junit.Test; + +import org.apache.catalina.util.IOTools; + +/** + * Reproduces what current appears to be a JVM bug. Note: This test case is not + * part of the Standard test suite that is execute by ant test. + */ +public class TestFlushableGZIPOutputStream { + + @Test + public void testBug52121() throws Exception { + + ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream(); + OutputStream output = new FlushableGZIPOutputStream(byteOutStream); + + File sourcesDir = new File("test/org/apache/coyote/http11/filters/"); + List parts = new ArrayList(); + byte[] part; + + part = loadFile(new File(sourcesDir, "bug52121-part1")); + parts.add(part); + flowBytes(part, output); + output.flush(); + + part = loadFile(new File(sourcesDir, "bug52121-part2")); + parts.add(part); + flowBytes(part, output); + output.flush(); + + part = "data2".getBytes("ASCII"); + parts.add(part); + output.write(part); + output.flush(); + + 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(); + int originalLength = 0; + for (byte[] bytes : parts) { + assertArrayEquals(bytes, Arrays.copyOfRange(decompressedBytes, + originalLength, originalLength + bytes.length)); + originalLength += bytes.length; + } + assertEquals(originalLength, decompressedBytes.length); + } + + /** + * Loads file into memory. + */ + private byte[] loadFile(File file) throws IOException { + ByteArrayOutputStream byteOutStream = new ByteArrayOutputStream(); + FileInputStream input = new FileInputStream(file); + try { + IOTools.flow(input, byteOutStream); + } finally { + input.close(); + } + return byteOutStream.toByteArray(); + } + + /** + * Writes data to the stream and returns the size of the file. + */ + private void flowBytes(byte[] bytes, OutputStream output) + throws IOException { + // Could use output.write(), but IOTools writes in small portions, and + // that is more natural + ByteArrayInputStream byteInStream = new ByteArrayInputStream(bytes); + try { + IOTools.flow(byteInStream, output); + } finally { + byteInStream.close(); + } + } +} Propchange: tomcat/trunk/test/org/apache/coyote/http11/filters/TestFlushableGZIPOutputStream.java ------------------------------------------------------------------------------ svn:eol-style = native --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org For additional commands, e-mail: dev-help@tomcat.apache.org