Return-Path: Delivered-To: apmail-commons-commits-archive@minotaur.apache.org Received: (qmail 17849 invoked from network); 5 Mar 2009 04:35:57 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 5 Mar 2009 04:35:57 -0000 Received: (qmail 65416 invoked by uid 500); 5 Mar 2009 04:35:56 -0000 Delivered-To: apmail-commons-commits-archive@commons.apache.org Received: (qmail 65354 invoked by uid 500); 5 Mar 2009 04:35:56 -0000 Mailing-List: contact commits-help@commons.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@commons.apache.org Delivered-To: mailing list commits@commons.apache.org Received: (qmail 65345 invoked by uid 99); 5 Mar 2009 04:35:56 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Mar 2009 20:35:56 -0800 X-ASF-Spam-Status: No, hits=-2000.0 required=10.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; Thu, 05 Mar 2009 04:35:54 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id EE8A42388975; Thu, 5 Mar 2009 04:35:32 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r750310 - /commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java Date: Thu, 05 Mar 2009 04:35:32 -0000 To: commits@commons.apache.org From: bodewig@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20090305043532.EE8A42388975@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: bodewig Date: Thu Mar 5 04:35:32 2009 New Revision: 750310 URL: http://svn.apache.org/viewvc?rev=750310&view=rev Log: ensure the same encoding is used for name and comment in all places. Submitted by Wolfgang Glas Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java Modified: commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java?rev=750310&r1=750309&r2=750310&view=diff ============================================================================== --- commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java (original) +++ commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java Thu Mar 5 04:35:32 2009 @@ -629,12 +629,16 @@ protected void writeLocalFileHeader(ZipArchiveEntry ze) throws IOException { boolean encodable = zipEncoding.canEncode(ze.getName()); - ByteBuffer name; + + final ZipEncoding entryEncoding; + if (!encodable && fallbackToUTF8) { - name = ZipEncodingHelper.UTF8_ZIP_ENCODING.encode(ze.getName()); + entryEncoding = ZipEncodingHelper.UTF8_ZIP_ENCODING; } else { - name = zipEncoding.encode(ze.getName()); + entryEncoding = zipEncoding; } + + ByteBuffer name = entryEncoding.encode(ze.getName()); if (createUnicodeExtraFields != UnicodeExtraFieldPolicy.NEVER) { @@ -653,7 +657,7 @@ if (createUnicodeExtraFields == UnicodeExtraFieldPolicy.ALWAYS || !commentEncodable) { - ByteBuffer commentB = this.zipEncoding.encode(comm); + ByteBuffer commentB = entryEncoding.encode(comm); ze.addExtraField(new UnicodeCommentExtraField(comm, commentB.array(), commentB.arrayOffset(), @@ -779,12 +783,16 @@ // CheckStyle:MagicNumber ON // file name length - ByteBuffer name; + final ZipEncoding entryEncoding; + if (!encodable && fallbackToUTF8) { - name = ZipEncodingHelper.UTF8_ZIP_ENCODING.encode(ze.getName()); + entryEncoding = ZipEncodingHelper.UTF8_ZIP_ENCODING; } else { - name = zipEncoding.encode(ze.getName()); + entryEncoding = zipEncoding; } + + ByteBuffer name = entryEncoding.encode(ze.getName()); + writeOut(ZipShort.getBytes(name.limit())); written += SHORT; @@ -798,12 +806,9 @@ if (comm == null) { comm = ""; } - ByteBuffer commentB; - if (!encodable && fallbackToUTF8) { - commentB = ZipEncodingHelper.UTF8_ZIP_ENCODING.encode(comm); - } else { - commentB = zipEncoding.encode(comm); - } + + ByteBuffer commentB = entryEncoding.encode(comm); + writeOut(ZipShort.getBytes(commentB.limit())); written += SHORT;