commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
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 GMT
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;
 



Mime
View raw message