commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r911740 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip: ZipArchiveInputStream.java ZipArchiveOutputStream.java ZipFile.java
Date Fri, 19 Feb 2010 08:41:23 GMT
Author: bodewig
Date: Fri Feb 19 08:41:23 2010
New Revision: 911740

URL: http://svn.apache.org/viewvc?rev=911740&view=rev
Log:
EFS in APPNOTE.TXT stands for 'Early Feature Specification' so our usage of it as 'use the
general purpose field to signal UTF8' is wrong.

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java?rev=911740&r1=911739&r2=911740&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStream.java
Fri Feb 19 08:41:23 2010
@@ -135,10 +135,10 @@
                             & ZipFile.NIBLET_MASK);
 
         final int generalPurposeFlag = ZipShort.getValue(lfh, off);
-        final boolean hasEFS = 
-            (generalPurposeFlag & ZipArchiveOutputStream.EFS_FLAG) != 0;
+        final boolean hasUTF8Flag = 
+            (generalPurposeFlag & ZipArchiveOutputStream.UFT8_NAMES_FLAG) != 0;
         final ZipEncoding entryEncoding =
-            hasEFS ? ZipEncodingHelper.UTF8_ZIP_ENCODING : zipEncoding;
+            hasUTF8Flag ? ZipEncodingHelper.UTF8_ZIP_ENCODING : zipEncoding;
         hasDataDescriptor = (generalPurposeFlag & 8) != 0;
 
         off += SHORT;
@@ -178,7 +178,7 @@
         readFully(extraData);
         current.setExtra(extraData);
 
-        if (!hasEFS && useUnicodeExtraFields) {
+        if (!hasUTF8Flag && useUnicodeExtraFields) {
             ZipUtil.setNameAndCommentFromExtraFields(current, fileName, null);
         }
         return current;

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java?rev=911740&r1=911739&r2=911740&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipArchiveOutputStream.java
Fri Feb 19 08:41:23 2010
@@ -94,11 +94,18 @@
      */
     static final String DEFAULT_ENCODING = ZipEncodingHelper.UTF8;
 
-     /**
+    /**
+     * General purpose flag, which indicates that filenames are
+     * written in utf-8.
+     */
+    public static final int UFT8_NAMES_FLAG = 1 << 11;
+
+    /**
      * General purpose flag, which indicates that filenames are
      * written in utf-8.
+     * @deprecated use {@link #UFT8_NAMES_FLAG} instead
      */
-    public static final int EFS_FLAG = 1 << 11;
+    public static final int EFS_FLAG = UFT8_NAMES_FLAG;
 
     /**
      * Current entry.
@@ -215,9 +222,10 @@
     private final OutputStream out;
 
     /**
-     * whether to use the EFS flag when writing UTF-8 filenames or not.
+     * whether to use the general purpose bit flag when writing UTF-8
+     * filenames or not.
      */
-    private boolean useEFS = true; 
+    private boolean useUTF8Flag = true; 
 
     /**
      * Whether to encode non-encodable file names as UTF-8.
@@ -290,7 +298,7 @@
     public void setEncoding(final String encoding) {
         this.encoding = encoding;
         this.zipEncoding = ZipEncodingHelper.getZipEncoding(encoding);
-        useEFS &= ZipEncodingHelper.isUTF8(encoding);
+        useUTF8Flag &= ZipEncodingHelper.isUTF8(encoding);
     }
 
     /**
@@ -309,7 +317,7 @@
      * <p>Defaults to true.</p>
      */
     public void setUseLanguageEncodingFlag(boolean b) {
-        useEFS = b && ZipEncodingHelper.isUTF8(encoding);
+        useUTF8Flag = b && ZipEncodingHelper.isUTF8(encoding);
     }
 
     /**
@@ -890,7 +898,7 @@
 
         // CheckStyle:MagicNumber OFF
         int versionNeededToExtract = 10;
-        int generalPurposeFlag = (useEFS || utfFallback) ? EFS_FLAG : 0;
+        int generalPurposeFlag = (useUTF8Flag || utfFallback) ? UFT8_NAMES_FLAG : 0;
         if (zipMethod == DEFLATED && raf == null) {
             // requires version 2 as we are going to store length info
             // in the data descriptor

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java?rev=911740&r1=911739&r2=911740&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipFile.java
Fri Feb 19 08:41:23 2010
@@ -178,8 +178,8 @@
         archive = new RandomAccessFile(f, "r");
         boolean success = false;
         try {
-            Map entriesWithoutEFS = populateFromCentralDirectory();
-            resolveLocalFileHeaderData(entriesWithoutEFS);
+            Map entriesWithoutUTF8Flag = populateFromCentralDirectory();
+            resolveLocalFileHeaderData(entriesWithoutUTF8Flag);
             success = true;
         } finally {
             if (!success) {
@@ -304,7 +304,7 @@
      */
     private Map populateFromCentralDirectory()
         throws IOException {
-        HashMap noEFS = new HashMap();
+        HashMap noUTF8Flag = new HashMap();
 
         positionAtCentralDirectory();
 
@@ -330,10 +330,10 @@
             off += SHORT; // skip version info
 
             final int generalPurposeFlag = ZipShort.getValue(cfh, off);
-            final boolean hasEFS = 
-                (generalPurposeFlag & ZipArchiveOutputStream.EFS_FLAG) != 0;
+            final boolean hasUTF8Flag = 
+                (generalPurposeFlag & ZipArchiveOutputStream.UFT8_NAMES_FLAG) != 0;
             final ZipEncoding entryEncoding =
-                hasEFS ? ZipEncodingHelper.UTF8_ZIP_ENCODING : zipEncoding;
+                hasUTF8Flag ? ZipEncodingHelper.UTF8_ZIP_ENCODING : zipEncoding;
 
             off += SHORT;
 
@@ -396,11 +396,11 @@
             archive.readFully(signatureBytes);
             sig = ZipLong.getValue(signatureBytes);
 
-            if (!hasEFS && useUnicodeExtraFields) {
-                noEFS.put(ze, new NameAndComment(fileName, comment));
+            if (!hasUTF8Flag && useUnicodeExtraFields) {
+                noUTF8Flag.put(ze, new NameAndComment(fileName, comment));
             }
         }
-        return noEFS;
+        return noUTF8Flag;
     }
 
     private static final int MIN_EOCD_SIZE =
@@ -495,7 +495,7 @@
      * <p>Also records the offsets for the data to read from the
      * entries.</p>
      */
-    private void resolveLocalFileHeaderData(Map entriesWithoutEFS)
+    private void resolveLocalFileHeaderData(Map entriesWithoutUTF8Flag)
         throws IOException {
         Enumeration e = getEntries();
         while (e.hasMoreElements()) {
@@ -527,9 +527,9 @@
             offsetEntry.dataOffset = offset + LFH_OFFSET_FOR_FILENAME_LENGTH
                 + SHORT + SHORT + fileNameLen + extraFieldLen;
 
-            if (entriesWithoutEFS.containsKey(ze)) {
+            if (entriesWithoutUTF8Flag.containsKey(ze)) {
                 String orig = ze.getName();
-                NameAndComment nc = (NameAndComment) entriesWithoutEFS.get(ze);
+                NameAndComment nc = (NameAndComment) entriesWithoutUTF8Flag.get(ze);
                 ZipUtil.setNameAndCommentFromExtraFields(ze, nc.name,
                                                          nc.comment);
                 if (!orig.equals(ze.getName())) {



Mime
View raw message