commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r909456 - in /commons/proper/compress/trunk/src/main/java/org/apache/commons/compress: archivers/ archivers/zip/ compressors/ compressors/bzip2/ compressors/gzip/
Date Fri, 12 Feb 2010 15:22:07 GMT
Author: bodewig
Date: Fri Feb 12 15:22:02 2010
New Revision: 909456

URL: http://svn.apache.org/viewvc?rev=909456&view=rev
Log:
make String comparisions locale-insensitive

Modified:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.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/compressors/CompressorStreamFactory.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2Utils.java
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/gzip/GzipUtils.java

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java?rev=909456&r1=909455&r2=909456&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/archivers/ArchiveStreamFactory.java
Fri Feb 12 15:22:02 2010
@@ -21,6 +21,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.Locale;
 
 import org.apache.commons.compress.archivers.ar.ArArchiveInputStream;
 import org.apache.commons.compress.archivers.ar.ArArchiveOutputStream;
@@ -71,6 +72,14 @@
  */
 public class ArchiveStreamFactory {
 
+    // constants used for case- and locale-insensitive comparisons.
+
+    private static final String AR_LC = "ar";
+    private static final String CPIO_LC = "cpio";
+    private static final String JAR_LC = "jar";
+    private static final String TAR_LC = "tar";
+    private static final String ZIP_LC = "zip";
+
     /**
      * Create an archive input stream from an archiver name and an input stream.
      * 
@@ -92,19 +101,21 @@
         	throw new IllegalArgumentException("InputStream must not be null.");
         }
 
-        if ("ar".equalsIgnoreCase(archiverName)) {
+        String archiverNameToCompare = archiverName.toLowerCase(Locale.ENGLISH);
+
+        if (AR_LC.equals(archiverNameToCompare)) {
             return new ArArchiveInputStream(in);
         }
-        if ("zip".equalsIgnoreCase(archiverName)) {
+        if (ZIP_LC.equals(archiverNameToCompare)) {
             return new ZipArchiveInputStream(in);
         }
-        if ("tar".equalsIgnoreCase(archiverName)) {
+        if (TAR_LC.equals(archiverNameToCompare)) {
             return new TarArchiveInputStream(in);
         }
-        if ("jar".equalsIgnoreCase(archiverName)) {
+        if (JAR_LC.equals(archiverNameToCompare)) {
             return new JarArchiveInputStream(in);
         }
-        if ("cpio".equalsIgnoreCase(archiverName)) {
+        if (CPIO_LC.equals(archiverNameToCompare)) {
             return new CpioArchiveInputStream(in);
         }
         
@@ -130,15 +141,21 @@
         	throw new IllegalArgumentException("OutputStream must not be null.");
         }
 
-        if ("ar".equalsIgnoreCase(archiverName)) {
+        String archiverNameToCompare = archiverName.toLowerCase(Locale.ENGLISH);
+
+        if (AR_LC.equals(archiverNameToCompare)) {
             return new ArArchiveOutputStream(out);
-        } else if ("zip".equalsIgnoreCase(archiverName)) {
+        }
+        if (ZIP_LC.equals(archiverNameToCompare)) {
             return new ZipArchiveOutputStream(out);
-        } else if ("tar".equalsIgnoreCase(archiverName)) {
+        }
+        if (TAR_LC.equals(archiverNameToCompare)) {
             return new TarArchiveOutputStream(out);
-        } else if ("jar".equalsIgnoreCase(archiverName)) {
+        }
+        if (JAR_LC.equals(archiverNameToCompare)) {
             return new JarArchiveOutputStream(out);
-        } else if ("cpio".equalsIgnoreCase(archiverName)) {
+        }
+        if (CPIO_LC.equals(archiverNameToCompare)) {
             return new CpioArchiveOutputStream(out);
         }
         throw new ArchiveException("Archiver: " + archiverName + " not found.");

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=909456&r1=909455&r2=909456&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
Fri Feb 12 15:22:02 2010
@@ -22,6 +22,7 @@
 import java.nio.charset.Charset;
 import java.nio.charset.UnsupportedCharsetException;
 import java.util.HashMap;
+import java.util.Locale;
 import java.util.Map;
 
 /**
@@ -191,6 +192,16 @@
     static final String UTF8 = "UTF8";
 
     /**
+     * name of the encoding UTF-8 used for comparisions.
+     */
+    private static final String UTF8_LC = UTF8.toLowerCase(Locale.ENGLISH);
+
+    /**
+     * variant name of the encoding UTF-8 used for comparisions.
+     */
+    private static final String UTF_DASH_8_LC = "utf-8";
+
+    /**
      * name of the encoding UTF-8
      */
     static final ZipEncoding UTF8_ZIP_ENCODING = new FallbackZipEncoding(UTF8);
@@ -239,7 +250,7 @@
             // check platform's default encoding
             encoding = System.getProperty("file.encoding");
         }
-        return UTF8.equalsIgnoreCase(encoding)
-            || "utf-8".equalsIgnoreCase(encoding);
+        String enc = encoding.toLowerCase(Locale.ENGLISH);
+        return UTF8_LC.equals(enc) || UTF_DASH_8_LC.equals(enc);
     }
 }

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java?rev=909456&r1=909455&r2=909456&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/CompressorStreamFactory.java
Fri Feb 12 15:22:02 2010
@@ -21,6 +21,7 @@
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.util.Locale;
 
 import org.apache.commons.compress.compressors.bzip2.BZip2CompressorInputStream;
 import org.apache.commons.compress.compressors.bzip2.BZip2CompressorOutputStream;
@@ -55,6 +56,9 @@
  */
 public class CompressorStreamFactory {
 
+    // constants used for case- and locale-insensitive comparisons.
+    private static final String BZ_LC = "bzip2";
+    private static final String GZ_LC = "gz";
 
     /**
      * Create an compressor input stream from an input stream, autodetecting
@@ -113,13 +117,15 @@
                     "Compressor name and stream must not be null.");
         }
 
+        String nameToCompare = name.toLowerCase(Locale.ENGLISH);
+
         try {
             
-            if ("gz".equalsIgnoreCase(name)) {
+            if (GZ_LC.equals(nameToCompare)) {
                 return new GzipCompressorInputStream(in);
             }
             
-            if ("bzip2".equalsIgnoreCase(name)) {
+            if (BZ_LC.equals(nameToCompare)) {
                 return new BZip2CompressorInputStream(in);
             }
             
@@ -147,13 +153,15 @@
                     "Compressor name and stream must not be null.");
         }
 
+        String nameToCompare = name.toLowerCase(Locale.ENGLISH);
+
         try {
 
-            if ("gz".equalsIgnoreCase(name)) {
+            if (GZ_LC.equals(nameToCompare)) {
                 return new GzipCompressorOutputStream(out);
-            } 
+            }
             
-            if ("bzip2".equalsIgnoreCase(name)) {
+            if (BZ_LC.equals(nameToCompare)) {
                 return new BZip2CompressorOutputStream(out);
             }
         

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2Utils.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2Utils.java?rev=909456&r1=909455&r2=909456&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2Utils.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/bzip2/BZip2Utils.java
Fri Feb 12 15:22:02 2010
@@ -19,6 +19,7 @@
 package org.apache.commons.compress.compressors.bzip2;
 
 import java.util.HashMap;
+import java.util.Locale;
 import java.util.Map;
 
 /**
@@ -58,7 +59,7 @@
      *         <code>false</code> otherwise
      */
     public static boolean isCompressedFilename(String filename) {
-        String lower = filename.toLowerCase();
+        String lower = filename.toLowerCase(Locale.ENGLISH);
         int n = lower.length();
         // Shortest suffix is three letters (.bz), longest is five (.tbz2)
         for (int i = 3; i <= 5 && i < n; i++) {
@@ -83,7 +84,7 @@
      * @return name of the corresponding uncompressed file
      */
     public static String getUncompressedFilename(String filename) {
-        String lower = filename.toLowerCase();
+        String lower = filename.toLowerCase(Locale.ENGLISH);
         int n = lower.length();
         // Shortest suffix is three letters (.bz), longest is five (.tbz2)
         for (int i = 3; i <= 5 && i < n; i++) {

Modified: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/gzip/GzipUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/gzip/GzipUtils.java?rev=909456&r1=909455&r2=909456&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/gzip/GzipUtils.java
(original)
+++ commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/gzip/GzipUtils.java
Fri Feb 12 15:22:02 2010
@@ -19,6 +19,7 @@
 package org.apache.commons.compress.compressors.gzip;
 
 import java.util.HashMap;
+import java.util.Locale;
 import java.util.Map;
 
 /**
@@ -76,7 +77,7 @@
      *         <code>false</code> otherwise
      */
     public static boolean isCompressedFilename(String filename) {
-        String lower = filename.toLowerCase();
+        String lower = filename.toLowerCase(Locale.ENGLISH);
         int n = lower.length();
         // Shortest suffix is two letters (_z), longest is five (.svgz)
         for (int i = 2; i <= 5 && i < n; i++) {
@@ -101,7 +102,7 @@
      * @return name of the corresponding uncompressed file
      */
     public static String getUncompressedFilename(String filename) {
-        String lower = filename.toLowerCase();
+        String lower = filename.toLowerCase(Locale.ENGLISH);
         int n = lower.length();
         // Shortest suffix is two letters (_z), longest is five (.svgz)
         for (int i = 2; i <= 5 && i < n; i++) {
@@ -125,7 +126,7 @@
      * @return name of the corresponding compressed file
      */
     public static String getCompressedFilename(String filename) {
-        String lower = filename.toLowerCase();
+        String lower = filename.toLowerCase(Locale.ENGLISH);
         int n = lower.length();
         // Shortest suffix is four letters (.svg), longest is five (.cpio)
         for (int i = 4; i <= 5 && i < n; i++) {



Mime
View raw message