commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r749906 - in /commons/sandbox/compress/trunk/src: main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
Date Wed, 04 Mar 2009 05:07:26 GMT
Author: bodewig
Date: Wed Mar  4 05:07:25 2009
New Revision: 749906

URL: http://svn.apache.org/viewvc?rev=749906&view=rev
Log:
Turn Unicode extra field handling into an enum since there are more than two options.  SANDBOX-176

Modified:
    commons/sandbox/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
    commons/sandbox/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.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=749906&r1=749905&r2=749906&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
Wed Mar  4 05:07:25 2009
@@ -231,7 +231,8 @@
     /**
      * whether to create UnicodePathExtraField-s for each entry.
      */
-    private boolean createUnicodeExtraFields = false;
+    private UnicodeExtraFieldPolicy createUnicodeExtraFields =
+        UnicodeExtraFieldPolicy.NEVER;
 
     /**
      * Creates a new ZIP OutputStream filtering the underlying stream.
@@ -314,11 +315,11 @@
     }
 
     /**
-     * Whether to create Unicode Extra Fields for all entries.
+     * Whether to create Unicode Extra Fields.
      *
-     * <p>Defaults to false.</p>
+     * <p>Defaults to NEVER.</p>
      */
-    public void setCreateUnicodeExtraFields(boolean b) {
+    public void setCreateUnicodeExtraFields(UnicodeExtraFieldPolicy b) {
         createUnicodeExtraFields = b;
     }
 
@@ -615,28 +616,30 @@
         boolean encodable = this.zipEncoding.canEncode(ze.getName());
         ByteBuffer name = this.zipEncoding.encode(ze.getName());
 
-        if (createUnicodeExtraFields) {
+        if (createUnicodeExtraFields != UnicodeExtraFieldPolicy.NEVER) {
 
-            /*            if (!encodable) { -- FIXME decide what to*/
+            if (createUnicodeExtraFields == UnicodeExtraFieldPolicy.ALWAYS
+                || !encodable) {
                 ze.addExtraField(new UnicodePathExtraField(ze.getName(),
                                                            name.array(),
                                                            name.arrayOffset(),
                                                            name.limit()));
-            /* } */
+            }
 
             String comm = ze.getComment();
             if (comm != null && !"".equals(comm)) {
 
                 boolean commentEncodable = this.zipEncoding.canEncode(comm);
 
-                /*            if (!commentEncodable) { -- FIXME decide what to*/
+                if (createUnicodeExtraFields == UnicodeExtraFieldPolicy.ALWAYS
+                    || !commentEncodable) {
                     ByteBuffer commentB = this.zipEncoding.encode(comm);
                     ze.addExtraField(new UnicodeCommentExtraField(comm,
                                                                   commentB.array(),
                                                                   commentB.arrayOffset(),
                                                                   commentB.limit())
                                      );
-                /* } */
+                }
             }
         }
 
@@ -930,4 +933,35 @@
         // general purpose bit flag
         writeOut(ZipShort.getBytes(generalPurposeFlag));
     }
+
+    /**
+     * enum that represents the possible policies for creating Unicode
+     * extra fields.
+     */
+    public static final class UnicodeExtraFieldPolicy {
+        /**
+         * Always create Unicode extra fields.
+         */
+        public static final UnicodeExtraFieldPolicy ALWAYS =
+            new UnicodeExtraFieldPolicy("always");
+        /**
+         * Never create Unicode extra fields.
+         */
+        public static final UnicodeExtraFieldPolicy NEVER =
+            new UnicodeExtraFieldPolicy("never");
+        /**
+         * Create Unicode extra fields for filenames that cannot be
+         * encoded using the specified encoding.
+         */
+        public static final UnicodeExtraFieldPolicy NOT_ENCODABLE =
+            new UnicodeExtraFieldPolicy("not encodable");
+
+        private final String name;
+        private UnicodeExtraFieldPolicy(String n) {
+            name = n;
+        }
+        public String toString() {
+            return name;
+        }
+    }
 }

Modified: commons/sandbox/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
URL: http://svn.apache.org/viewvc/commons/sandbox/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java?rev=749906&r1=749905&r2=749906&view=diff
==============================================================================
--- commons/sandbox/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
(original)
+++ commons/sandbox/compress/trunk/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
Wed Mar  4 05:07:25 2009
@@ -161,7 +161,11 @@
             zos = new ZipArchiveOutputStream(file);
             zos.setEncoding(encoding);
             zos.setUseLanguageEncodingFlag(withEFS);
-            zos.setCreateUnicodeExtraFields(!withExplicitUnicodeExtra);
+            zos.setCreateUnicodeExtraFields(withExplicitUnicodeExtra ? 
+                                            ZipArchiveOutputStream
+                                            .UnicodeExtraFieldPolicy.NEVER
+                                            : ZipArchiveOutputStream
+                                            .UnicodeExtraFieldPolicy.ALWAYS);
 
             ZipArchiveEntry ze = new ZipArchiveEntry(OIL_BARREL_TXT);
             if (withExplicitUnicodeExtra



Mime
View raw message