commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1407854 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip: ExtraFieldUtils.java ZipEncodingHelper.java ZipMethod.java
Date Sat, 10 Nov 2012 17:27:15 GMT
Author: bodewig
Date: Sat Nov 10 17:27:14 2012
New Revision: 1407854

URL: http://svn.apache.org/viewvc?rev=1407854&view=rev
Log:
Avoid some threading issues with HashMap

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEncodingHelper.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipMethod.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java?rev=1407854&r1=1407853&r2=1407854&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ExtraFieldUtils.java
Sat Nov 10 17:27:14 2012
@@ -18,9 +18,9 @@
 package org.apache.commons.compress.archivers.zip;
 
 import java.util.ArrayList;
-import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.concurrent.ConcurrentHashMap;
 import java.util.zip.ZipException;
 
 /**
@@ -38,7 +38,7 @@ public class ExtraFieldUtils {
     private static final Map<ZipShort, Class<?>> implementations;
 
     static {
-        implementations = new HashMap<ZipShort, Class<?>>();
+        implementations = new ConcurrentHashMap<ZipShort, Class<?>>();
         register(AsiExtraField.class);
         register(JarMarker.class);
         register(UnicodePathExtraField.class);

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEncodingHelper.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEncodingHelper.java?rev=1407854&r1=1407853&r2=1407854&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEncodingHelper.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipEncodingHelper.java
Sat Nov 10 17:27:14 2012
@@ -21,6 +21,7 @@ package org.apache.commons.compress.arch
 import java.nio.ByteBuffer;
 import java.nio.charset.Charset;
 import java.nio.charset.UnsupportedCharsetException;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 
@@ -67,7 +68,8 @@ public abstract class ZipEncodingHelper 
     private static final Map<String, SimpleEncodingHolder> simpleEncodings;
 
     static {
-        simpleEncodings = new HashMap<String, SimpleEncodingHolder>();
+        Map<String, SimpleEncodingHolder> se =
+            new HashMap<String, SimpleEncodingHolder>();
 
         char[] cp437_high_chars =
             new char[] { 0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0,
@@ -95,11 +97,11 @@ public abstract class ZipEncodingHelper 
 
         SimpleEncodingHolder cp437 = new SimpleEncodingHolder(cp437_high_chars);
 
-        simpleEncodings.put("CP437",cp437);
-        simpleEncodings.put("Cp437",cp437);
-        simpleEncodings.put("cp437",cp437);
-        simpleEncodings.put("IBM437",cp437);
-        simpleEncodings.put("ibm437",cp437);
+        se.put("CP437", cp437);
+        se.put("Cp437", cp437);
+        se.put("cp437", cp437);
+        se.put("IBM437", cp437);
+        se.put("ibm437", cp437);
 
         char[] cp850_high_chars =
             new char[] { 0x00c7, 0x00fc, 0x00e9, 0x00e2, 0x00e4, 0x00e0,
@@ -127,11 +129,12 @@ public abstract class ZipEncodingHelper 
 
         SimpleEncodingHolder cp850 = new SimpleEncodingHolder(cp850_high_chars);
 
-        simpleEncodings.put("CP850",cp850);
-        simpleEncodings.put("Cp850",cp850);
-        simpleEncodings.put("cp850",cp850);
-        simpleEncodings.put("IBM850",cp850);
-        simpleEncodings.put("ibm850",cp850);
+        se.put("CP850", cp850);
+        se.put("Cp850", cp850);
+        se.put("cp850", cp850);
+        se.put("IBM850", cp850);
+        se.put("ibm850", cp850);
+        simpleEncodings = Collections.unmodifiableMap(se);
     }
 
     /**

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipMethod.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipMethod.java?rev=1407854&r1=1407853&r2=1407854&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipMethod.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/zip/ZipMethod.java
Sat Nov 10 17:27:14 2012
@@ -17,6 +17,7 @@
  */
 package org.apache.commons.compress.archivers.zip;
 
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Map;
 import java.util.zip.ZipEntry;
@@ -167,13 +168,14 @@ public enum ZipMethod {
 
     private final int code;
 
-    private static final Map<Integer, ZipMethod> codeToEnum =
-        new HashMap<Integer, ZipMethod>();
+    private static final Map<Integer, ZipMethod> codeToEnum;
 
     static {
+        Map<Integer, ZipMethod> cte = new HashMap<Integer, ZipMethod>();
         for (ZipMethod method : values()) {
-            codeToEnum.put(Integer.valueOf(method.getCode()), method);
+            cte.put(Integer.valueOf(method.getCode()), method);
         }
+        codeToEnum = Collections.unmodifiableMap(cte);
     }
 
     /**



Mime
View raw message