commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bode...@apache.org
Subject svn commit: r1196953 - in /commons/proper/compress/trunk/src: main/java/org/apache/commons/compress/compressors/xz/XZUtils.java test/java/org/apache/commons/compress/compressors/XZUtilsTestCase.java
Date Thu, 03 Nov 2011 06:06:26 GMT
Author: bodewig
Date: Thu Nov  3 06:06:26 2011
New Revision: 1196953

URL: http://svn.apache.org/viewvc?rev=1196953&view=rev
Log:
XZUtils modelled after GzipUtils

Added:
    commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/xz/XZUtils.java
      - copied, changed from r1196949, commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/gzip/GzipUtils.java
    commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/XZUtilsTestCase.java
      - copied, changed from r1196949, commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/GzipUtilsTestCase.java

Copied: commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/xz/XZUtils.java
(from r1196949, 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/xz/XZUtils.java?p2=commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/xz/XZUtils.java&p1=commons/proper/compress/trunk/src/main/java/org/apache/commons/compress/compressors/gzip/GzipUtils.java&r1=1196949&r2=1196953&rev=1196953&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/xz/XZUtils.java
Thu Nov  3 06:06:26 2011
@@ -16,30 +16,31 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-package org.apache.commons.compress.compressors.gzip;
+package org.apache.commons.compress.compressors.xz;
 
 import java.util.HashMap;
 import java.util.Locale;
 import java.util.Map;
 
 /**
- * Utility code for the gzip compression format.
+ * Utility code for the xz compression format.
  * @ThreadSafe
+ * @since Commons Compress 1.4
  */
-public class GzipUtils {
+public class XZUtils {
 
     /**
-     * Map from common filename suffixes to the suffixes that identify gzipped
-     * versions of those file types. For example: from ".tar" to ".tgz".
+     * Map from common filename suffixes to the suffixes that identify xzped
+     * versions of those file types. For example: from ".tar" to ".txz".
      */
     private static final Map<String, String> compressSuffix =
         new HashMap<String, String>();
 
     /**
-     * Map from common filename suffixes of gzipped files to the corresponding
+     * Map from common filename suffixes of xzped files to the corresponding
      * suffixes of uncompressed files. For example: from ".tgz" to ".tar".
      * <p>
-     * This map also contains gzip-specific suffixes like ".gz" and "-z".
+     * This map also contains xz-specific suffixes like ".gz" and "-z".
      * These suffixes are mapped to the empty string, as they should simply
      * be removed from the filename when the file is uncompressed.
      */
@@ -47,42 +48,30 @@ public class GzipUtils {
         new HashMap<String, String>();
 
     static {
-        compressSuffix.put(".tar", ".tgz");
-        compressSuffix.put(".svg", ".svgz");
-        compressSuffix.put(".cpio", ".cpgz");
-        compressSuffix.put(".wmf", ".wmz");
-        compressSuffix.put(".emf", ".emz");
-
-        uncompressSuffix.put(".tgz", ".tar");
-        uncompressSuffix.put(".taz", ".tar");
-        uncompressSuffix.put(".svgz", ".svg");
-        uncompressSuffix.put(".cpgz", ".cpio");
-        uncompressSuffix.put(".wmz", ".wmf");
-        uncompressSuffix.put(".emz", ".emf");
-        uncompressSuffix.put(".gz", "");
-        uncompressSuffix.put(".z", "");
-        uncompressSuffix.put("-gz", "");
-        uncompressSuffix.put("-z", "");
-        uncompressSuffix.put("_z", "");
+        compressSuffix.put(".tar", ".txz");
+
+        uncompressSuffix.put(".txz", ".tar");
+        uncompressSuffix.put(".xz", "");
+        uncompressSuffix.put("-xz", "");
     }
     // N.B. if any shorter or longer keys are added, ensure the for loop limits are changed
 
     /** Private constructor to prevent instantiation of this utility class. */
-    private GzipUtils() {
+    private XZUtils() {
     }
 
     /**
-     * Detects common gzip suffixes in the given filename.
+     * Detects common xz suffixes in the given filename.
      *
      * @param filename name of a file
-     * @return <code>true</code> if the filename has a common gzip suffix,
+     * @return <code>true</code> if the filename has a common xz suffix,
      *         <code>false</code> otherwise
      */
     public static boolean isCompressedFilename(String filename) {
         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++) {
+        // Shortest suffix is three letters (.xz), longest is four (.txz)
+        for (int i = 3; i <= 4 && i < n; i++) {
             if (uncompressSuffix.containsKey(lower.substring(n - i))) {
                 return true;
             }
@@ -91,13 +80,13 @@ public class GzipUtils {
     }
 
     /**
-     * Maps the given name of a gzip-compressed file to the name that the
+     * Maps the given name of a xz-compressed file to the name that the
      * file should have after uncompression. Commonly used file type specific
-     * suffixes like ".tgz" or ".svgz" are automatically detected and
-     * correctly mapped. For example the name "package.tgz" is mapped to
-     * "package.tar". And any filenames with the generic ".gz" suffix
-     * (or any other generic gzip suffix) is mapped to a name without that
-     * suffix. If no gzip suffix is detected, then the filename is returned
+     * suffixes like ".txz" are automatically detected and
+     * correctly mapped. For example the name "package.txz" is mapped to
+     * "package.tar". And any filenames with the generic ".xz" suffix
+     * (or any other generic xz suffix) is mapped to a name without that
+     * suffix. If no xz suffix is detected, then the filename is returned
      * unmapped.
      *
      * @param filename name of a file
@@ -106,8 +95,8 @@ public class GzipUtils {
     public static String getUncompressedFilename(String filename) {
         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++) {
+        // Shortest suffix is three letters (.xz), longest is four (.txz)
+        for (int i = 3; i <= 4 && i < n; i++) {
             Object suffix = uncompressSuffix.get(lower.substring(n - i));
             if (suffix != null) {
                 return filename.substring(0, n - i) + suffix;
@@ -118,10 +107,10 @@ public class GzipUtils {
 
     /**
      * Maps the given filename to the name that the file should have after
-     * compression with gzip. Common file types with custom suffixes for
+     * compression with xz. Common file types with custom suffixes for
      * compressed versions are automatically detected and correctly mapped.
-     * For example the name "package.tar" is mapped to "package.tgz". If no
-     * custom mapping is applicable, then the default ".gz" suffix is appended
+     * For example the name "package.tar" is mapped to "package.txz". If no
+     * custom mapping is applicable, then the default ".xz" suffix is appended
      * to the filename.
      *
      * @param filename name of a file
@@ -130,15 +119,15 @@ public class GzipUtils {
     public static String getCompressedFilename(String filename) {
         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++) {
+        // Shortest suffix is three letters (.xz), longest is four (.txz)
+        for (int i = 3; i <= 4 && i < n; i++) {
             Object suffix = compressSuffix.get(lower.substring(n - i));
             if (suffix != null) {
                 return filename.substring(0, n - i) + suffix;
             }
         }
         // No custom suffix found, just append the default .gz
-        return filename + ".gz";
+        return filename + ".xz";
     }
 
 }

Copied: commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/XZUtilsTestCase.java
(from r1196949, commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/GzipUtilsTestCase.java)
URL: http://svn.apache.org/viewvc/commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/XZUtilsTestCase.java?p2=commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/XZUtilsTestCase.java&p1=commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/GzipUtilsTestCase.java&r1=1196949&r2=1196953&rev=1196953&view=diff
==============================================================================
--- commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/GzipUtilsTestCase.java
(original)
+++ commons/proper/compress/trunk/src/test/java/org/apache/commons/compress/compressors/XZUtilsTestCase.java
Thu Nov  3 06:06:26 2011
@@ -18,83 +18,51 @@
  */
 package org.apache.commons.compress.compressors;
 
-import org.apache.commons.compress.compressors.gzip.GzipUtils;
+import org.apache.commons.compress.compressors.xz.XZUtils;
 
 import junit.framework.TestCase;
 
-public class GzipUtilsTestCase extends TestCase {
+public class XZUtilsTestCase extends TestCase {
 
     public void testIsCompressedFilename() {
-        assertFalse(GzipUtils.isCompressedFilename(""));
-        assertFalse(GzipUtils.isCompressedFilename(".gz"));
+        assertFalse(XZUtils.isCompressedFilename(""));
+        assertFalse(XZUtils.isCompressedFilename(".xz"));
 
-        assertTrue(GzipUtils.isCompressedFilename("x.tgz"));
-        assertTrue(GzipUtils.isCompressedFilename("x.taz"));
-        assertTrue(GzipUtils.isCompressedFilename("x.svgz"));
-        assertTrue(GzipUtils.isCompressedFilename("x.cpgz"));
-        assertTrue(GzipUtils.isCompressedFilename("x.wmz"));
-        assertTrue(GzipUtils.isCompressedFilename("x.emz"));
-        assertTrue(GzipUtils.isCompressedFilename("x.gz"));
-        assertTrue(GzipUtils.isCompressedFilename("x.z"));
-        assertTrue(GzipUtils.isCompressedFilename("x-gz"));
-        assertTrue(GzipUtils.isCompressedFilename("x-z"));
-        assertTrue(GzipUtils.isCompressedFilename("x_z"));
-
-        assertFalse(GzipUtils.isCompressedFilename("xxgz"));
-        assertFalse(GzipUtils.isCompressedFilename("xzz"));
-        assertFalse(GzipUtils.isCompressedFilename("xaz"));
-
-        assertTrue(GzipUtils.isCompressedFilename("x.SVGZ"));
-        assertTrue(GzipUtils.isCompressedFilename("x.Svgz"));
-        assertTrue(GzipUtils.isCompressedFilename("x.svGZ"));
-
-        assertFalse(GzipUtils.isCompressedFilename("x.wmz "));
-        assertFalse(GzipUtils.isCompressedFilename("x.wmz\n"));
-        assertFalse(GzipUtils.isCompressedFilename("x.wmz.y"));
+        assertTrue(XZUtils.isCompressedFilename("x.txz"));
+        assertTrue(XZUtils.isCompressedFilename("x.xz"));
+        assertTrue(XZUtils.isCompressedFilename("x-xz"));
+
+        assertFalse(XZUtils.isCompressedFilename("xxgz"));
+        assertFalse(XZUtils.isCompressedFilename("xzz"));
+        assertFalse(XZUtils.isCompressedFilename("xaz"));
+
+        assertFalse(XZUtils.isCompressedFilename("x.txz "));
+        assertFalse(XZUtils.isCompressedFilename("x.txz\n"));
+        assertFalse(XZUtils.isCompressedFilename("x.txz.y"));
     }
 
     public void testGetUncompressedFilename() {
-        assertEquals("", GzipUtils.getUncompressedFilename(""));
-        assertEquals(".gz", GzipUtils.getUncompressedFilename(".gz"));
+        assertEquals("", XZUtils.getUncompressedFilename(""));
+        assertEquals(".xz", XZUtils.getUncompressedFilename(".xz"));
 
-        assertEquals("x.tar", GzipUtils.getUncompressedFilename("x.tgz"));
-        assertEquals("x.tar", GzipUtils.getUncompressedFilename("x.taz"));
-        assertEquals("x.svg", GzipUtils.getUncompressedFilename("x.svgz"));
-        assertEquals("x.cpio", GzipUtils.getUncompressedFilename("x.cpgz"));
-        assertEquals("x.wmf", GzipUtils.getUncompressedFilename("x.wmz"));
-        assertEquals("x.emf", GzipUtils.getUncompressedFilename("x.emz"));
-        assertEquals("x", GzipUtils.getUncompressedFilename("x.gz"));
-        assertEquals("x", GzipUtils.getUncompressedFilename("x.z"));
-        assertEquals("x", GzipUtils.getUncompressedFilename("x-gz"));
-        assertEquals("x", GzipUtils.getUncompressedFilename("x-z"));
-        assertEquals("x", GzipUtils.getUncompressedFilename("x_z"));
-
-        assertEquals("x.svg", GzipUtils.getUncompressedFilename("x.SVGZ"));
-        assertEquals("X.svg", GzipUtils.getUncompressedFilename("X.SVGZ"));
-        assertEquals("X.svg", GzipUtils.getUncompressedFilename("X.svGZ"));
-
-        assertEquals("x.wmz ", GzipUtils.getUncompressedFilename("x.wmz "));
-        assertEquals("x.wmz\n", GzipUtils.getUncompressedFilename("x.wmz\n"));
-        assertEquals("x.wmz.y", GzipUtils.getUncompressedFilename("x.wmz.y"));
+        assertEquals("x.tar", XZUtils.getUncompressedFilename("x.txz"));
+        assertEquals("x", XZUtils.getUncompressedFilename("x.xz"));
+        assertEquals("x", XZUtils.getUncompressedFilename("x-xz"));
+
+        assertEquals("x.txz ", XZUtils.getUncompressedFilename("x.txz "));
+        assertEquals("x.txz\n", XZUtils.getUncompressedFilename("x.txz\n"));
+        assertEquals("x.txz.y", XZUtils.getUncompressedFilename("x.txz.y"));
     }
 
     public void testGetCompressedFilename() {
-        assertEquals(".gz", GzipUtils.getCompressedFilename(""));
-        assertEquals("x.gz", GzipUtils.getCompressedFilename("x"));
+        assertEquals(".xz", XZUtils.getCompressedFilename(""));
+        assertEquals("x.xz", XZUtils.getCompressedFilename("x"));
 
-        assertEquals("x.tgz", GzipUtils.getCompressedFilename("x.tar"));
-        assertEquals("x.svgz", GzipUtils.getCompressedFilename("x.svg"));
-        assertEquals("x.cpgz", GzipUtils.getCompressedFilename("x.cpio"));
-        assertEquals("x.wmz", GzipUtils.getCompressedFilename("x.wmf"));
-        assertEquals("x.emz", GzipUtils.getCompressedFilename("x.emf"));
-
-        assertEquals("x.svgz", GzipUtils.getCompressedFilename("x.SVG"));
-        assertEquals("X.svgz", GzipUtils.getCompressedFilename("X.SVG"));
-        assertEquals("X.svgz", GzipUtils.getCompressedFilename("X.svG"));
-
-        assertEquals("x.wmf .gz", GzipUtils.getCompressedFilename("x.wmf "));
-        assertEquals("x.wmf\n.gz", GzipUtils.getCompressedFilename("x.wmf\n"));
-        assertEquals("x.wmf.y.gz", GzipUtils.getCompressedFilename("x.wmf.y"));
+        assertEquals("x.txz", XZUtils.getCompressedFilename("x.tar"));
+
+        assertEquals("x.wmf .xz", XZUtils.getCompressedFilename("x.wmf "));
+        assertEquals("x.wmf\n.xz", XZUtils.getCompressedFilename("x.wmf\n"));
+        assertEquals("x.wmf.y.xz", XZUtils.getCompressedFilename("x.wmf.y"));
     }
 
 }



Mime
View raw message