Return-Path: Delivered-To: apmail-ant-dev-archive@www.apache.org Received: (qmail 56758 invoked from network); 9 Nov 2004 07:36:49 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur-2.apache.org with SMTP; 9 Nov 2004 07:36:49 -0000 Received: (qmail 65592 invoked by uid 500); 9 Nov 2004 07:36:41 -0000 Delivered-To: apmail-ant-dev-archive@ant.apache.org Received: (qmail 65351 invoked by uid 500); 9 Nov 2004 07:36:09 -0000 Mailing-List: contact dev-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Developers List" Reply-To: "Ant Developers List" Delivered-To: mailing list dev@ant.apache.org Received: (qmail 65337 invoked by uid 99); 9 Nov 2004 07:36:09 -0000 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: pass (hermes.apache.org: local policy) Received: from [210.245.44.131] (HELO mail.fts-vn.com) (210.245.44.131) by apache.org (qpsmtpd/0.28) with ESMTP; Mon, 08 Nov 2004 23:36:09 -0800 Received: from firewall ([210.245.44.130] helo=[172.16.1.104]) by mail.fts-vn.com with esmtp (Exim 4.34) id 1CRQVp-0002Cx-3k for dev@ant.apache.org; Tue, 09 Nov 2004 14:33:57 +0700 Message-ID: <4190734A.40207@it.fts-vn.com> Date: Tue, 09 Nov 2004 14:35:38 +0700 From: Kevin Jackson User-Agent: Mozilla Thunderbird 0.8 (Windows/20040913) X-Accept-Language: en-us, en MIME-Version: 1.0 To: Ant Developers List Subject: [Patch] performance fix for ZipOutputStream Content-Type: multipart/mixed; boundary="------------030309030509090401080106" X-Virus-Checked: Checked X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N --------------030309030509090401080106 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Patch changes toDosTime and the calls to toDosTime (in writeLocalFileHeader and writeCentralFileHeader) It may help to alleviate the performance bug that has been reported, I've included a unit test, but I cannot run a performance test right now, so in effect it may slow everything down even more (but I really doubt it :)). Submitted in the hope that it will help or at least be of benefit. Kev --------------030309030509090401080106 Content-Type: text/plain; name="patch.txt" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch.txt" Index: ZipOutputStream.java =================================================================== RCS file: /home/cvspublic/ant/src/main/org/apache/tools/zip/ZipOutputStream.java,v retrieving revision 1.25 diff -u -r1.25 ZipOutputStream.java --- ZipOutputStream.java 5 Nov 2004 14:46:25 -0000 1.25 +++ ZipOutputStream.java 9 Nov 2004 07:30:57 -0000 @@ -25,7 +25,6 @@ import java.io.RandomAccessFile; import java.io.UnsupportedEncodingException; import java.util.Calendar; -import java.util.Date; import java.util.Hashtable; import java.util.Vector; import java.util.zip.CRC32; @@ -219,6 +218,12 @@ public static final int STORED = ZipEntry.STORED; /** + * Calendar instance + * + */ + private static Calendar cal = Calendar.getInstance(); + + /** * Creates a new ZIP OutputStream filtering the underlying stream. * * @since 1.1 @@ -581,7 +586,7 @@ written += 2; // last mod. time and date - writeOut(toDosTime(new Date(ze.getTime())).getBytes()); + writeOut(toDosTime(ze.getTime())); written += 4; // CRC @@ -669,7 +674,7 @@ written += 2; // last mod. time and date - writeOut(toDosTime(new Date(ze.getTime())).getBytes()); + writeOut(toDosTime(ze.getTime())); written += 4; // CRC @@ -769,14 +774,13 @@ * * @since 1.1 */ - protected static ZipLong toDosTime(Date time) { - Calendar cal = Calendar.getInstance(); - cal.setTime(time); + protected static byte[] toDosTime(long time) { + cal.setTimeInMillis(time); int year = cal.get(Calendar.YEAR); - int month = cal.get(Calendar.MONTH) + 1; if (year < 1980) { - return DOS_TIME_MIN; + return DOS_TIME_MIN.getBytes(); } + int month = cal.get(Calendar.MONTH) + 1; long value = ((year - 1980) << 25) | (month << 21) | (cal.get(Calendar.DAY_OF_MONTH) << 16) @@ -789,7 +793,7 @@ result[1] = (byte) ((value & 0xFF00) >> 8); result[2] = (byte) ((value & 0xFF0000) >> 16); result[3] = (byte) ((value & 0xFF000000L) >> 24); - return new ZipLong(result); + return result; } /** Index: ZipOutputStreamTest.java =================================================================== RCS file: ZipOutputStreamTest.java diff -N ZipOutputStreamTest.java --- /dev/null 1 Jan 1970 00:00:00 -0000 +++ ZipOutputStreamTest.java 1 Jan 1970 00:00:00 -0000 @@ -0,0 +1,81 @@ +package org.apache.tools.zip; + +import java.util.Calendar; +import java.util.Date; + +import junit.framework.Test; +import junit.framework.TestCase; +import junit.framework.TestSuite; + + +/** + * @author it-kevin + */ +public class ZipOutputStreamTest extends TestCase { + + private Calendar cal = Calendar.getInstance(); + private ZipLong zl; + private Date date; + private final ZipLong DOS_TIME_MIN = new ZipLong(0x00002100L); + + /* + * @see TestCase#setUp() + */ + protected void setUp() throws Exception { + super.setUp(); + date = new Date(); + cal.setTime(date); + int year = cal.get(Calendar.YEAR); + if (year < 1980) { + zl = DOS_TIME_MIN; + } + int month = cal.get(Calendar.MONTH) + 1; + long value = ((year - 1980) << 25) + | (month << 21) + | (cal.get(Calendar.DAY_OF_MONTH) << 16) + | (cal.get(Calendar.HOUR_OF_DAY) << 11) + | (cal.get(Calendar.MINUTE) << 5) + | (cal.get(Calendar.SECOND) >> 1); + + byte[] result = new byte[4]; + result[0] = (byte) ((value & 0xFF)); + result[1] = (byte) ((value & 0xFF00) >> 8); + result[2] = (byte) ((value & 0xFF0000) >> 16); + result[3] = (byte) ((value & 0xFF000000L) >> 24); + zl = new ZipLong(result); + } + + + + /* + * @see TestCase#tearDown() + */ + protected void tearDown() throws Exception { + super.tearDown(); + } + + /** + * Constructor for ZipOutputStreamTest. + * @param arg0 + */ + public ZipOutputStreamTest(String arg0) { + super(arg0); + } + + public static Test suite() { + TestSuite suite = new TestSuite(); + suite.addTest(new ZipOutputStreamTest("testToDosTime")); + return suite; + } + + public void testToDosTime() { + try { + assertEquals(zl.getValue(),new ZipLong(ZipOutputStream.toDosTime(date.getTime())).getValue()); + } catch (Exception e) { + e.printStackTrace(); + fail(); + } + } + + +} --------------030309030509090401080106 Content-Type: text/plain; charset=us-ascii --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org For additional commands, e-mail: dev-help@ant.apache.org --------------030309030509090401080106--