Replace magic strings "UTF-8", "US-ASCII", and so on with references to a new .util class CharsetNames (like in other commons components.) The Charsets class will be more useful when [compress] moves to Java 6 and can use String#getBytes(Charset) instead of String#getBytes(String).
git-svn-id: https://svn.apache.org/repos/asf/commons/proper/compress/trunk@1307926 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
index ada4746..7803671 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStream.java
@@ -35,6 +35,7 @@
import org.apache.commons.compress.archivers.zip.ZipEncoding;
import org.apache.commons.compress.archivers.zip.ZipEncodingHelper;
import org.apache.commons.compress.utils.ArchiveUtils;
+import org.apache.commons.compress.utils.CharsetNames;
/**
* The TarInputStream reads a UNIX tar archive as an InputStream.
@@ -330,7 +331,7 @@
while((ch = i.read()) != -1) {
read++;
if (ch == '='){ // end of keyword
- String keyword = coll.toString("UTF-8");
+ String keyword = coll.toString(CharsetNames.UTF_8);
// Get rest of entry
byte[] rest = new byte[len - read];
int got = i.read(rest);
@@ -343,7 +344,7 @@
}
// Drop trailing NL
String value = new String(rest, 0,
- len - read - 1, "UTF-8");
+ len - read - 1, CharsetNames.UTF_8);
headers.put(keyword, value);
break;
}
diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
index 2ee5544..10a77db 100644
--- a/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
+++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStream.java
@@ -28,6 +28,7 @@
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.archivers.zip.ZipEncoding;
import org.apache.commons.compress.archivers.zip.ZipEncodingHelper;
+import org.apache.commons.compress.utils.CharsetNames;
import org.apache.commons.compress.utils.CountingOutputStream;
/**
@@ -465,7 +466,7 @@
+ 3 /* blank, equals and newline */
+ 2 /* guess 9 < actual length < 100 */;
String line = len + " " + key + "=" + value + "\n";
- int actualLength = line.getBytes("UTF-8").length;
+ int actualLength = line.getBytes(CharsetNames.UTF_8).length;
while (len != actualLength) {
// Adjust for cases where length < 10 or > 100
// or where UTF-8 encoding isn't a single octet
@@ -474,11 +475,11 @@
// first pass so we'd need a second.
len = actualLength;
line = len + " " + key + "=" + value + "\n";
- actualLength = line.getBytes("UTF-8").length;
+ actualLength = line.getBytes(CharsetNames.UTF_8).length;
}
w.write(line);
}
- byte[] data = w.toString().getBytes("UTF-8");
+ byte[] data = w.toString().getBytes(CharsetNames.UTF_8);
pex.setSize(data.length);
putArchiveEntry(pex);
write(data);
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/AbstractUnicodeExtraField.java b/src/main/java/org/apache/commons/compress/archivers/zip/AbstractUnicodeExtraField.java
index 6c28ec1..614c58c 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/AbstractUnicodeExtraField.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/AbstractUnicodeExtraField.java
@@ -22,6 +22,8 @@
import java.util.zip.CRC32;
import java.util.zip.ZipException;
+import org.apache.commons.compress.utils.CharsetNames;
+
/**
* A common base class for Unicode extra information extra fields.
* @NotThreadSafe
@@ -52,7 +54,7 @@
nameCRC32 = crc32.getValue();
try {
- unicodeName = text.getBytes("UTF-8");
+ unicodeName = text.getBytes(CharsetNames.UTF_8);
} catch (UnsupportedEncodingException e) {
throw new RuntimeException("FATAL: UTF-8 encoding not supported.", e);
}
diff --git a/src/main/java/org/apache/commons/compress/archivers/zip/ZipEncodingHelper.java b/src/main/java/org/apache/commons/compress/archivers/zip/ZipEncodingHelper.java
index de002fa..97aa821 100644
--- a/src/main/java/org/apache/commons/compress/archivers/zip/ZipEncodingHelper.java
+++ b/src/main/java/org/apache/commons/compress/archivers/zip/ZipEncodingHelper.java
@@ -24,6 +24,8 @@
import java.util.HashMap;
import java.util.Map;
+import org.apache.commons.compress.utils.CharsetNames;
+
/**
* Static helper functions for robustly encoding filenames in zip files.
*/
@@ -193,7 +195,7 @@
/**
* variant name of the encoding UTF-8 used for comparisions.
*/
- private static final String UTF_DASH_8 = "utf-8";
+ private static final String UTF_DASH_8 = CharsetNames.UTF_8;
/**
* name of the encoding UTF-8
diff --git a/src/main/java/org/apache/commons/compress/utils/CharsetNames.java b/src/main/java/org/apache/commons/compress/utils/CharsetNames.java
new file mode 100644
index 0000000..e7b9ab9
--- /dev/null
+++ b/src/main/java/org/apache/commons/compress/utils/CharsetNames.java
@@ -0,0 +1,109 @@
+package org.apache.commons.compress.utils;
+
+/**
+ * Character encoding names required of every implementation of the Java platform.
+ *
+ * From the Java documentation <a href="http://download.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard
+ * charsets</a>:
+ * <p>
+ * <cite>Every implementation of the Java platform is required to support the following character encodings. Consult the
+ * release documentation for your implementation to see if any other encodings are supported. Consult the release
+ * documentation for your implementation to see if any other encodings are supported. </cite>
+ * </p>
+ *
+ * <ul>
+ * <li><code>US-ASCII</code><br/>
+ * Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the Unicode character set.</li>
+ * <li><code>ISO-8859-1</code><br/>
+ * ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1.</li>
+ * <li><code>UTF-8</code><br/>
+ * Eight-bit Unicode Transformation Format.</li>
+ * <li><code>UTF-16BE</code><br/>
+ * Sixteen-bit Unicode Transformation Format, big-endian byte order.</li>
+ * <li><code>UTF-16LE</code><br/>
+ * Sixteen-bit Unicode Transformation Format, little-endian byte order.</li>
+ * <li><code>UTF-16</code><br/>
+ * Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order mark (either order
+ * accepted on input, big-endian used on output.)</li>
+ * </ul>
+ *
+ * This perhaps would best belong in the [lang] project. Even if a similar interface is defined in [lang], it is not
+ * foreseen that [codec] would be made to depend on [lang].
+ *
+ * @see <a href="http://download.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
+ * @author Apache Software Foundation
+ * @since 1.4
+ * @version $Id$
+ */
+public class CharsetNames {
+ /**
+ * CharEncodingISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1. </p>
+ * <p>
+ * Every implementation of the Java platform is required to support this character encoding.
+ * </p>
+ *
+ * @see <a href="http://download.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
+ */
+ public static final String ISO_8859_1 = "ISO-8859-1";
+
+ /**
+ * <p>
+ * Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set.
+ * </p>
+ * <p>
+ * Every implementation of the Java platform is required to support this character encoding.
+ * </p>
+ *
+ * @see <a href="http://download.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
+ */
+ public static final String US_ASCII = "US-ASCII";
+
+ /**
+ * <p>
+ * Sixteen-bit Unicode Transformation Format, The byte order specified by a mandatory initial byte-order mark
+ * (either order accepted on input, big-endian used on output)
+ * </p>
+ * <p>
+ * Every implementation of the Java platform is required to support this character encoding.
+ * </p>
+ *
+ * @see <a href="http://download.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
+ */
+ public static final String UTF_16 = "UTF-16";
+
+ /**
+ * <p>
+ * Sixteen-bit Unicode Transformation Format, big-endian byte order.
+ * </p>
+ * <p>
+ * Every implementation of the Java platform is required to support this character encoding.
+ * </p>
+ *
+ * @see <a href="http://download.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
+ */
+ public static final String UTF_16BE = "UTF-16BE";
+
+ /**
+ * <p>
+ * Sixteen-bit Unicode Transformation Format, little-endian byte order.
+ * </p>
+ * <p>
+ * Every implementation of the Java platform is required to support this character encoding.
+ * </p>
+ *
+ * @see <a href="http://download.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
+ */
+ public static final String UTF_16LE = "UTF-16LE";
+
+ /**
+ * <p>
+ * Eight-bit Unicode Transformation Format.
+ * </p>
+ * <p>
+ * Every implementation of the Java platform is required to support this character encoding.
+ * </p>
+ *
+ * @see <a href="http://download.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
+ */
+ public static final String UTF_8 = "UTF-8";
+}
\ No newline at end of file
diff --git a/src/main/java/org/apache/commons/compress/utils/Charsets.java b/src/main/java/org/apache/commons/compress/utils/Charsets.java
new file mode 100644
index 0000000..c07e7b8
--- /dev/null
+++ b/src/main/java/org/apache/commons/compress/utils/Charsets.java
@@ -0,0 +1,142 @@
+package org.apache.commons.compress.utils;
+
+import java.nio.charset.Charset;
+import java.nio.charset.UnsupportedCharsetException;
+
+/**
+ * Charsets required of every implementation of the Java platform.
+ *
+ * From the Java documentation <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard
+ * charsets</a>:
+ * <p>
+ * <cite>Every implementation of the Java platform is required to support the following character encodings. Consult the
+ * release documentation for your implementation to see if any other encodings are supported. Consult the release
+ * documentation for your implementation to see if any other encodings are supported. </cite>
+ * </p>
+ *
+ * <ul>
+ * <li><code>US-ASCII</code><br/>
+ * Seven-bit ASCII, a.k.a. ISO646-US, a.k.a. the Basic Latin block of the Unicode character set.</li>
+ * <li><code>ISO-8859-1</code><br/>
+ * ISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1.</li>
+ * <li><code>UTF-8</code><br/>
+ * Eight-bit Unicode Transformation Format.</li>
+ * <li><code>UTF-16BE</code><br/>
+ * Sixteen-bit Unicode Transformation Format, big-endian byte order.</li>
+ * <li><code>UTF-16LE</code><br/>
+ * Sixteen-bit Unicode Transformation Format, little-endian byte order.</li>
+ * <li><code>UTF-16</code><br/>
+ * Sixteen-bit Unicode Transformation Format, byte order specified by a mandatory initial byte-order mark (either order
+ * accepted on input, big-endian used on output.)</li>
+ * </ul>
+ *
+ * This perhaps would best belong in the Commons Lang project. Even if a similar class is defined in Commons Lang, it is
+ * not foreseen that Commons Codec would be made to depend on Commons Lang.
+ *
+ * @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
+ * @author Apache Software Foundation
+ * @since 1.4
+ * @version $Id$
+ */
+public class Charsets {
+
+ //
+ // This class should only contain Charset instances for required encodings. This guarantees that it will load correctly and
+ // without delay on all Java platforms.
+ //
+
+ /**
+ * Returns the given Charset or the default Charset if the given Charset is null.
+ *
+ * @param charset
+ * A charset or null.
+ * @return the given Charset or the default Charset if the given Charset is null
+ */
+ public static Charset toCharset(Charset charset) {
+ return charset == null ? Charset.defaultCharset() : charset;
+ }
+
+ /**
+ * Returns a Charset for the named charset. If the name is null, return the default Charset.
+ *
+ * @param charset
+ * The name of the requested charset, may be null.
+ * @return a Charset for the named charset
+ * @throws UnsupportedCharsetException
+ * If the named charset is unavailable
+ */
+ public static Charset toCharset(String charset) {
+ return charset == null ? Charset.defaultCharset() : Charset.forName(charset);
+ }
+
+ /**
+ * CharsetNamesISO Latin Alphabet No. 1, a.k.a. ISO-LATIN-1. </p>
+ * <p>
+ * Every implementation of the Java platform is required to support this character encoding.
+ * </p>
+ *
+ * @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
+ */
+ public static final Charset ISO_8859_1 = Charset.forName(CharsetNames.ISO_8859_1);
+
+ /**
+ * <p>
+ * Seven-bit ASCII, also known as ISO646-US, also known as the Basic Latin block of the Unicode character set.
+ * </p>
+ * <p>
+ * Every implementation of the Java platform is required to support this character encoding.
+ * </p>
+ *
+ * @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
+ */
+ public static final Charset US_ASCII = Charset.forName(CharsetNames.US_ASCII);
+
+ /**
+ * <p>
+ * Sixteen-bit Unicode Transformation Format, The byte order specified by a mandatory initial byte-order mark
+ * (either order accepted on input, big-endian used on output)
+ * </p>
+ * <p>
+ * Every implementation of the Java platform is required to support this character encoding.
+ * </p>
+ *
+ * @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
+ */
+ public static final Charset UTF_16 = Charset.forName(CharsetNames.UTF_16);
+
+ /**
+ * <p>
+ * Sixteen-bit Unicode Transformation Format, big-endian byte order.
+ * </p>
+ * <p>
+ * Every implementation of the Java platform is required to support this character encoding.
+ * </p>
+ *
+ * @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
+ */
+ public static final Charset UTF_16BE = Charset.forName(CharsetNames.UTF_16BE);
+
+ /**
+ * <p>
+ * Sixteen-bit Unicode Transformation Format, little-endian byte order.
+ * </p>
+ * <p>
+ * Every implementation of the Java platform is required to support this character encoding.
+ * </p>
+ *
+ * @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
+ */
+ public static final Charset UTF_16LE = Charset.forName(CharsetNames.UTF_16LE);
+
+ /**
+ * <p>
+ * Eight-bit Unicode Transformation Format.
+ * </p>
+ * <p>
+ * Every implementation of the Java platform is required to support this character encoding.
+ * </p>
+ *
+ * @see <a href="http://docs.oracle.com/javase/6/docs/api/java/nio/charset/Charset.html">Standard charsets</a>
+ */
+ public static final Charset UTF_8 = Charset.forName(CharsetNames.UTF_8);
+}
diff --git a/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java b/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java
index 88a1160..7ed8db5 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ArchiveStreamFactoryTest.java
@@ -18,11 +18,13 @@
*/
package org.apache.commons.compress.archivers;
-import java.io.ByteArrayInputStream;
-import org.junit.Test;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import java.io.ByteArrayInputStream;
+
+import org.junit.Test;
+
public class ArchiveStreamFactoryTest {
/**
diff --git a/src/test/java/org/apache/commons/compress/archivers/CpioTestCase.java b/src/test/java/org/apache/commons/compress/archivers/CpioTestCase.java
index 5e5c96e..3e189a7 100644
--- a/src/test/java/org/apache/commons/compress/archivers/CpioTestCase.java
+++ b/src/test/java/org/apache/commons/compress/archivers/CpioTestCase.java
@@ -28,9 +28,9 @@
import org.apache.commons.compress.AbstractTestCase;
import org.apache.commons.compress.archivers.cpio.CpioArchiveEntry;
-import org.apache.commons.compress.archivers.cpio.CpioConstants;
import org.apache.commons.compress.archivers.cpio.CpioArchiveInputStream;
import org.apache.commons.compress.archivers.cpio.CpioArchiveOutputStream;
+import org.apache.commons.compress.archivers.cpio.CpioConstants;
import org.apache.commons.compress.utils.IOUtils;
public final class CpioTestCase extends AbstractTestCase {
diff --git a/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java b/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java
index cb066d2..ee672af 100644
--- a/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java
+++ b/src/test/java/org/apache/commons/compress/archivers/JarTestCase.java
@@ -24,11 +24,10 @@
import java.io.InputStream;
import java.io.OutputStream;
+import org.apache.commons.compress.AbstractTestCase;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.utils.IOUtils;
-import org.apache.commons.compress.AbstractTestCase;
-
public final class JarTestCase extends AbstractTestCase {
public void testJarArchiveCreation() throws Exception {
final File output = new File(dir, "bla.jar");
diff --git a/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java b/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java
index 7a96dae..d77fab2 100644
--- a/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java
+++ b/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java
@@ -29,6 +29,7 @@
import org.apache.commons.compress.archivers.tar.TarArchiveEntry;
import org.apache.commons.compress.archivers.tar.TarArchiveInputStream;
import org.apache.commons.compress.archivers.tar.TarArchiveOutputStream;
+import org.apache.commons.compress.utils.CharsetNames;
import org.apache.commons.compress.utils.IOUtils;
public final class TarTestCase extends AbstractTestCase {
@@ -53,7 +54,7 @@
public void testTarArchiveLongNameCreation() throws Exception {
String name = "testdata/12345678901234567890123456789012345678901234567890123456789012345678901234567890123456.xml";
- byte[] bytes = name.getBytes("UTF-8");
+ byte[] bytes = name.getBytes(CharsetNames.UTF_8);
assertEquals(bytes.length, 99);
final File output = new File(dir, "bla.tar");
@@ -118,7 +119,7 @@
final File input = getFile("COMPRESS-114.tar");
final InputStream is = new FileInputStream(input);
final ArchiveInputStream in = new TarArchiveInputStream(is,
- "iso-8859-1");
+ CharsetNames.ISO_8859_1);
TarArchiveEntry entry = (TarArchiveEntry)in.getNextEntry();
assertEquals("3\u00b1\u00b1\u00b1F06\u00b1W2345\u00b1ZB\u00b1la\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1BLA", entry.getName());
entry = (TarArchiveEntry)in.getNextEntry();
diff --git a/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java
index ee152d6..7a6f63d 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveInputStreamTest.java
@@ -20,6 +20,7 @@
import java.io.BufferedInputStream;
import java.io.FileInputStream;
+
import org.apache.commons.compress.AbstractTestCase;
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.utils.ArchiveUtils;
diff --git a/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java
index 119da31..643bc85 100644
--- a/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStreamTest.java
@@ -19,11 +19,12 @@
package org.apache.commons.compress.archivers.ar;
import java.io.ByteArrayOutputStream;
-import java.io.FileOutputStream;
import java.io.File;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
+
import org.apache.commons.compress.AbstractTestCase;
public class ArArchiveOutputStreamTest extends AbstractTestCase {
diff --git a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioUtilTest.java b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioUtilTest.java
index c68f997..329d481 100644
--- a/src/test/java/org/apache/commons/compress/archivers/cpio/CpioUtilTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/cpio/CpioUtilTest.java
@@ -18,10 +18,11 @@
*/
package org.apache.commons.compress.archivers.cpio;
-import org.junit.Test;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
public class CpioUtilTest {
@Test
diff --git a/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveEntryTest.java b/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveEntryTest.java
index 4303472..8dad403 100644
--- a/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveEntryTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveEntryTest.java
@@ -18,9 +18,10 @@
*/
package org.apache.commons.compress.archivers.dump;
-import org.junit.Test;
import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
public class DumpArchiveEntryTest {
@Test
public void publicNameAddsTrailingSlashForDirectories() {
diff --git a/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStreamTest.java
index decf2e2..e034936 100644
--- a/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveInputStreamTest.java
@@ -19,8 +19,9 @@
package org.apache.commons.compress.archivers.dump;
import java.io.FileInputStream;
-import org.apache.commons.compress.archivers.ArchiveException;
+
import org.apache.commons.compress.AbstractTestCase;
+import org.apache.commons.compress.archivers.ArchiveException;
public class DumpArchiveInputStreamTest extends AbstractTestCase {
diff --git a/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveUtilTest.java b/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveUtilTest.java
index 6e631e4..2aceca3 100644
--- a/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveUtilTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/dump/DumpArchiveUtilTest.java
@@ -18,9 +18,10 @@
*/
package org.apache.commons.compress.archivers.dump;
-import org.junit.Test;
import static org.junit.Assert.assertEquals;
+import org.junit.Test;
+
public class DumpArchiveUtilTest {
@Test
diff --git a/src/test/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStreamTest.java
index ea905ab..e97fb1a 100644
--- a/src/test/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/jar/JarArchiveOutputStreamTest.java
@@ -21,6 +21,7 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
+
import junit.framework.TestCase;
import org.apache.commons.compress.AbstractTestCase;
diff --git a/src/test/java/org/apache/commons/compress/archivers/memory/MemoryArchiveEntry.java b/src/test/java/org/apache/commons/compress/archivers/memory/MemoryArchiveEntry.java
index 930dc1b..f2314af 100644
--- a/src/test/java/org/apache/commons/compress/archivers/memory/MemoryArchiveEntry.java
+++ b/src/test/java/org/apache/commons/compress/archivers/memory/MemoryArchiveEntry.java
@@ -19,6 +19,7 @@
package org.apache.commons.compress.archivers.memory;
import java.util.Date;
+
import org.apache.commons.compress.archivers.ArchiveEntry;
public final class MemoryArchiveEntry implements ArchiveEntry {
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/BigFilesIT.java b/src/test/java/org/apache/commons/compress/archivers/tar/BigFilesIT.java
index 92e30b3..4c42a50 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/BigFilesIT.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/BigFilesIT.java
@@ -18,14 +18,14 @@
package org.apache.commons.compress.archivers.tar;
-import java.util.Random;
-
-import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
+import java.util.Random;
+
import org.apache.commons.compress.compressors.gzip.GzipCompressorInputStream;
+import org.junit.Test;
public class BigFilesIT {
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java
index fd686cb..15a9088 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/SparseFilesTest.java
@@ -22,6 +22,7 @@
import java.io.FileInputStream;
import java.net.URI;
import java.net.URL;
+
import junit.framework.TestCase;
public class SparseFilesTest extends TestCase {
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
index 07401ad..1cf2ccc 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveEntryTest.java
@@ -23,6 +23,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Locale;
+
import junit.framework.TestCase;
import org.apache.commons.compress.AbstractTestCase;
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
index 151522c..5e4f258 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveInputStreamTest.java
@@ -18,6 +18,9 @@
package org.apache.commons.compress.archivers.tar;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -27,9 +30,9 @@
import java.util.Date;
import java.util.Map;
import java.util.TimeZone;
+
+import org.apache.commons.compress.utils.CharsetNames;
import org.junit.Test;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
public class TarArchiveInputStreamTest {
@@ -37,7 +40,7 @@
public void readSimplePaxHeader() throws Exception {
Map<String, String> headers = new TarArchiveInputStream(null)
.parsePaxHeaders(new ByteArrayInputStream("30 atime=1321711775.972059463\n"
- .getBytes("UTF-8")));
+ .getBytes(CharsetNames.UTF_8)));
assertEquals(1, headers.size());
assertEquals("1321711775.972059463", headers.get("atime"));
}
@@ -46,7 +49,7 @@
public void readPaxHeaderWithEmbeddedNewline() throws Exception {
Map<String, String> headers = new TarArchiveInputStream(null)
.parsePaxHeaders(new ByteArrayInputStream("28 comment=line1\nline2\nand3\n"
- .getBytes("UTF-8")));
+ .getBytes(CharsetNames.UTF_8)));
assertEquals(1, headers.size());
assertEquals("line1\nline2\nand3", headers.get("comment"));
}
@@ -55,9 +58,9 @@
public void readNonAsciiPaxHeader() throws Exception {
String ae = "\u00e4";
String line = "11 path="+ ae + "\n";
- assertEquals(11, line.getBytes("UTF-8").length);
+ assertEquals(11, line.getBytes(CharsetNames.UTF_8).length);
Map<String, String> headers = new TarArchiveInputStream(null)
- .parsePaxHeaders(new ByteArrayInputStream(line.getBytes("UTF-8")));
+ .parsePaxHeaders(new ByteArrayInputStream(line.getBytes(CharsetNames.UTF_8)));
assertEquals(1, headers.size());
assertEquals(ae, headers.get("path"));
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
index 59c247f..26d8fe0 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarArchiveOutputStreamTest.java
@@ -31,6 +31,7 @@
import org.apache.commons.compress.AbstractTestCase;
import org.apache.commons.compress.archivers.ArchiveOutputStream;
import org.apache.commons.compress.archivers.ArchiveStreamFactory;
+import org.apache.commons.compress.utils.CharsetNames;
public class TarArchiveOutputStreamTest extends AbstractTestCase {
@@ -114,7 +115,7 @@
+ TarConstants.MODELEN
+ TarConstants.UIDLEN
+ TarConstants.GIDLEN, 12,
- "UTF-8"));
+ CharsetNames.UTF_8));
TarArchiveInputStream tin =
new TarArchiveInputStream(new ByteArrayInputStream(data));
TarArchiveEntry e = tin.getNextTarEntry();
@@ -130,8 +131,8 @@
+ TarConstants.MODELEN
+ TarConstants.UIDLEN
+ TarConstants.GIDLEN, 12,
- "UTF-8"));
- assertEquals("6 a=b\n", new String(data, 512, 6, "UTF-8"));
+ CharsetNames.UTF_8));
+ assertEquals("6 a=b\n", new String(data, 512, 6, CharsetNames.UTF_8));
}
public void testPaxHeadersWithLength99() throws Exception {
@@ -146,10 +147,10 @@
+ TarConstants.MODELEN
+ TarConstants.UIDLEN
+ TarConstants.GIDLEN, 12,
- "UTF-8"));
+ CharsetNames.UTF_8));
assertEquals("99 a=0123456789012345678901234567890123456789"
+ "01234567890123456789012345678901234567890123456789"
- + "012\n", new String(data, 512, 99, "UTF-8"));
+ + "012\n", new String(data, 512, 99, CharsetNames.UTF_8));
}
public void testPaxHeadersWithLength101() throws Exception {
@@ -164,10 +165,10 @@
+ TarConstants.MODELEN
+ TarConstants.UIDLEN
+ TarConstants.GIDLEN, 12,
- "UTF-8"));
+ CharsetNames.UTF_8));
assertEquals("101 a=0123456789012345678901234567890123456789"
+ "01234567890123456789012345678901234567890123456789"
- + "0123\n", new String(data, 512, 101, "UTF-8"));
+ + "0123\n", new String(data, 512, 101, CharsetNames.UTF_8));
}
private byte[] writePaxHeader(Map<String, String> m) throws Exception {
@@ -200,7 +201,7 @@
tos.closeArchiveEntry();
byte[] data = bos.toByteArray();
assertEquals("160 path=" + n + "\n",
- new String(data, 512, 160, "UTF-8"));
+ new String(data, 512, 160, CharsetNames.UTF_8));
TarArchiveInputStream tin =
new TarArchiveInputStream(new ByteArrayInputStream(data));
TarArchiveEntry e = tin.getNextTarEntry();
@@ -251,7 +252,7 @@
+ TarConstants.UIDLEN
+ TarConstants.GIDLEN
+ TarConstants.SIZELEN, 12,
- "UTF-8"));
+ CharsetNames.UTF_8));
TarArchiveInputStream tin =
new TarArchiveInputStream(new ByteArrayInputStream(data));
TarArchiveEntry e = tin.getNextTarEntry();
@@ -287,7 +288,7 @@
tos.close();
byte[] data = bos.toByteArray();
assertEquals("11 path=" + n + "\n",
- new String(data, 512, 11, "UTF-8"));
+ new String(data, 512, 11, CharsetNames.UTF_8));
TarArchiveInputStream tin =
new TarArchiveInputStream(new ByteArrayInputStream(data));
TarArchiveEntry e = tin.getNextTarEntry();
@@ -308,7 +309,7 @@
tos.close();
byte[] data = bos.toByteArray();
assertEquals("15 linkpath=" + n + "\n",
- new String(data, 512, 15, "UTF-8"));
+ new String(data, 512, 15, CharsetNames.UTF_8));
TarArchiveInputStream tin =
new TarArchiveInputStream(new ByteArrayInputStream(data));
TarArchiveEntry e = tin.getNextTarEntry();
diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java
index fb793c8..3bc3b60 100644
--- a/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarUtilsTest.java
@@ -19,8 +19,10 @@
package org.apache.commons.compress.archivers.tar;
import junit.framework.TestCase;
+
import org.apache.commons.compress.archivers.zip.ZipEncoding;
import org.apache.commons.compress.archivers.zip.ZipEncodingHelper;
+import org.apache.commons.compress.utils.CharsetNames;
public class TarUtilsTest extends TestCase {
@@ -46,7 +48,7 @@
byte [] buffer;
final long MAX_OCTAL = 077777777777L; // Allowed 11 digits
final String maxOctal = "77777777777 "; // Maximum valid octal
- buffer = maxOctal.getBytes("UTF-8");
+ buffer = maxOctal.getBytes(CharsetNames.UTF_8);
value = TarUtils.parseOctal(buffer,0, buffer.length);
assertEquals(MAX_OCTAL, value);
buffer[buffer.length-1]=0;
@@ -80,25 +82,25 @@
fail("Expected IllegalArgumentException - not all NULs");
} catch (IllegalArgumentException expected) {
}
- buffer = "abcdef ".getBytes("UTF-8"); // Invalid input
+ buffer = "abcdef ".getBytes(CharsetNames.UTF_8); // Invalid input
try {
TarUtils.parseOctal(buffer,0, buffer.length);
fail("Expected IllegalArgumentException");
} catch (IllegalArgumentException expected) {
}
- buffer = "77777777777".getBytes("UTF-8"); // Invalid input - no trailer
+ buffer = "77777777777".getBytes(CharsetNames.UTF_8); // Invalid input - no trailer
try {
TarUtils.parseOctal(buffer,0, buffer.length);
fail("Expected IllegalArgumentException - no trailer");
} catch (IllegalArgumentException expected) {
}
- buffer = " 0 07 ".getBytes("UTF-8"); // Invalid - embedded space
+ buffer = " 0 07 ".getBytes(CharsetNames.UTF_8); // Invalid - embedded space
try {
TarUtils.parseOctal(buffer,0, buffer.length);
fail("Expected IllegalArgumentException - embedded space");
} catch (IllegalArgumentException expected) {
}
- buffer = " 0\00007 ".getBytes("UTF-8"); // Invalid - embedded NUL
+ buffer = " 0\00007 ".getBytes(CharsetNames.UTF_8); // Invalid - embedded NUL
try {
TarUtils.parseOctal(buffer,0, buffer.length);
fail("Expected IllegalArgumentException - embedded NUL");
@@ -175,13 +177,13 @@
public void testNegative() throws Exception {
byte [] buffer = new byte[22];
TarUtils.formatUnsignedOctalString(-1, buffer, 0, buffer.length);
- assertEquals("1777777777777777777777", new String(buffer, "UTF-8"));
+ assertEquals("1777777777777777777777", new String(buffer, CharsetNames.UTF_8));
}
public void testOverflow() throws Exception {
byte [] buffer = new byte[8-1]; // a lot of the numbers have 8-byte buffers (nul term)
TarUtils.formatUnsignedOctalString(07777777L, buffer, 0, buffer.length);
- assertEquals("7777777", new String(buffer, "UTF-8"));
+ assertEquals("7777777", new String(buffer, CharsetNames.UTF_8));
try {
TarUtils.formatUnsignedOctalString(017777777L, buffer, 0, buffer.length);
fail("Should have cause IllegalArgumentException");
@@ -198,7 +200,7 @@
public void testRoundEncoding() throws Exception {
// COMPRESS-114
- ZipEncoding enc = ZipEncodingHelper.getZipEncoding("iso-8859-1");
+ ZipEncoding enc = ZipEncodingHelper.getZipEncoding(CharsetNames.ISO_8859_1);
String s = "0302-0601-3\u00b1\u00b1\u00b1F06\u00b1W220\u00b1ZB\u00b1LALALA\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1\u00b1CAN\u00b1\u00b1DC\u00b1\u00b1\u00b104\u00b1060302\u00b1MOE.model";
byte buff[] = new byte[100];
int len = TarUtils.formatNameBytes(s, buff, 0, buff.length, enc);
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/EncryptedArchiveTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/EncryptedArchiveTest.java
index c73bf4f..1a5b973 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/EncryptedArchiveTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/EncryptedArchiveTest.java
@@ -24,6 +24,7 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
+
import junit.framework.TestCase;
public class EncryptedArchiveTest extends TestCase {
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/GeneralPurposeBitTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/GeneralPurposeBitTest.java
index 0e9b15e..d457915 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/GeneralPurposeBitTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/GeneralPurposeBitTest.java
@@ -20,6 +20,7 @@
package org.apache.commons.compress.archivers.zip;
import java.util.Arrays;
+
import junit.framework.TestCase;
public class GeneralPurposeBitTest extends TestCase {
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/Lister.java b/src/test/java/org/apache/commons/compress/archivers/zip/Lister.java
index 540bf55..2233b69 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/Lister.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/Lister.java
@@ -25,6 +25,7 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
+
import org.apache.commons.compress.archivers.ArchiveEntry;
import org.apache.commons.compress.utils.IOUtils;
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/Maven221MultiVolumeTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/Maven221MultiVolumeTest.java
index dab20c5..1774ca8 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/Maven221MultiVolumeTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/Maven221MultiVolumeTest.java
@@ -25,10 +25,10 @@
import java.net.URISyntaxException;
import java.net.URL;
-import org.apache.commons.compress.archivers.ArchiveEntry;
-
import junit.framework.TestCase;
+import org.apache.commons.compress.archivers.ArchiveEntry;
+
/**
* JUnit 3 testcase for a multi-volume zip file.
*
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/TestZipEncodings.java b/src/test/java/org/apache/commons/compress/archivers/zip/TestZipEncodings.java
index fa070b9..2e51c6a 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/TestZipEncodings.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/TestZipEncodings.java
@@ -24,6 +24,8 @@
import junit.framework.TestCase;
+import org.apache.commons.compress.utils.CharsetNames;
+
/**
* Test zip encodings.
*/
@@ -138,9 +140,9 @@
assertEquals(testBytes, encoded);
assertEquals(false, enc.canEncode(UNENC_STRING));
- assertEquals("%U2016".getBytes("US-ASCII"), enc.encode(UNENC_STRING));
+ assertEquals("%U2016".getBytes(CharsetNames.US_ASCII), enc.encode(UNENC_STRING));
assertEquals(false, enc.canEncode(BAD_STRING));
- assertEquals(BAD_STRING_ENC.getBytes("US-ASCII"),
+ assertEquals(BAD_STRING_ENC.getBytes(CharsetNames.US_ASCII),
enc.encode(BAD_STRING));
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
index a2d28c6..2d0ef4e 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/UTF8ZipFilesTest.java
@@ -31,24 +31,23 @@
import java.util.zip.CRC32;
import org.apache.commons.compress.AbstractTestCase;
+import org.apache.commons.compress.utils.CharsetNames;
public class UTF8ZipFilesTest extends AbstractTestCase {
- private static final String UTF_8 = "utf-8";
private static final String CP437 = "cp437";
- private static final String US_ASCII = "US-ASCII";
private static final String ASCII_TXT = "ascii.txt";
private static final String EURO_FOR_DOLLAR_TXT = "\u20AC_for_Dollar.txt";
private static final String OIL_BARREL_TXT = "\u00D6lf\u00E4sser.txt";
public void testUtf8FileRoundtripExplicitUnicodeExtra()
throws IOException {
- testFileRoundtrip(UTF_8, true, true);
+ testFileRoundtrip(CharsetNames.UTF_8, true, true);
}
public void testUtf8FileRoundtripNoEFSExplicitUnicodeExtra()
throws IOException {
- testFileRoundtrip(UTF_8, false, true);
+ testFileRoundtrip(CharsetNames.UTF_8, false, true);
}
public void testCP437FileRoundtripExplicitUnicodeExtra()
@@ -58,17 +57,17 @@
public void testASCIIFileRoundtripExplicitUnicodeExtra()
throws IOException {
- testFileRoundtrip(US_ASCII, false, true);
+ testFileRoundtrip(CharsetNames.US_ASCII, false, true);
}
public void testUtf8FileRoundtripImplicitUnicodeExtra()
throws IOException {
- testFileRoundtrip(UTF_8, true, false);
+ testFileRoundtrip(CharsetNames.UTF_8, true, false);
}
public void testUtf8FileRoundtripNoEFSImplicitUnicodeExtra()
throws IOException {
- testFileRoundtrip(UTF_8, false, false);
+ testFileRoundtrip(CharsetNames.UTF_8, false, false);
}
public void testCP437FileRoundtripImplicitUnicodeExtra()
@@ -78,7 +77,7 @@
public void testASCIIFileRoundtripImplicitUnicodeExtra()
throws IOException {
- testFileRoundtrip(US_ASCII, false, false);
+ testFileRoundtrip(CharsetNames.US_ASCII, false, false);
}
/*
@@ -172,9 +171,9 @@
file.deleteOnExit();
ZipArchiveInputStream zi = null;
try {
- createTestFile(file, US_ASCII, false, true);
+ createTestFile(file, CharsetNames.US_ASCII, false, true);
FileInputStream archive = new FileInputStream(file);
- zi = new ZipArchiveInputStream(archive, US_ASCII, true);
+ zi = new ZipArchiveInputStream(archive, CharsetNames.US_ASCII, true);
assertEquals(OIL_BARREL_TXT, zi.getNextEntry().getName());
assertEquals(EURO_FOR_DOLLAR_TXT, zi.getNextEntry().getName());
assertEquals(ASCII_TXT, zi.getNextEntry().getName());
@@ -192,8 +191,8 @@
file.deleteOnExit();
ZipFile zf = null;
try {
- createTestFile(file, US_ASCII, false, true);
- zf = new ZipFile(file, US_ASCII, true);
+ createTestFile(file, CharsetNames.US_ASCII, false, true);
+ zf = new ZipFile(file, CharsetNames.US_ASCII, true);
assertNotNull(zf.getEntry(ASCII_TXT));
assertNotNull(zf.getEntry(EURO_FOR_DOLLAR_TXT));
assertNotNull(zf.getEntry(OIL_BARREL_TXT));
@@ -277,7 +276,7 @@
}
zos.putArchiveEntry(ze);
- zos.write("Hello, world!".getBytes("US-ASCII"));
+ zos.write("Hello, world!".getBytes(CharsetNames.US_ASCII));
zos.closeArchiveEntry();
ze = new ZipArchiveEntry(EURO_FOR_DOLLAR_TXT);
@@ -293,7 +292,7 @@
}
zos.putArchiveEntry(ze);
- zos.write("Give me your money!".getBytes("US-ASCII"));
+ zos.write("Give me your money!".getBytes(CharsetNames.US_ASCII));
zos.closeArchiveEntry();
ze = new ZipArchiveEntry(ASCII_TXT);
@@ -310,7 +309,7 @@
}
zos.putArchiveEntry(ze);
- zos.write("ascii".getBytes("US-ASCII"));
+ zos.write("ascii".getBytes(CharsetNames.US_ASCII));
zos.closeArchiveEntry();
zos.finish();
@@ -369,7 +368,7 @@
assertEquals(crc.getValue(), ucpf.getNameCRC32());
assertEquals(expectedName, new String(ucpf.getUnicodeName(),
- UTF_8));
+ CharsetNames.UTF_8));
}
}
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraFieldTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraFieldTest.java
index 6021479..7d7ca2b 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraFieldTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/Zip64ExtendedInformationExtraFieldTest.java
@@ -20,6 +20,7 @@
import java.math.BigInteger;
import java.util.zip.ZipException;
+
import junit.framework.TestCase;
public class Zip64ExtendedInformationExtraFieldTest extends TestCase {
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportIT.java b/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportIT.java
index 0387df6..2ee9e0a 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportIT.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/Zip64SupportIT.java
@@ -18,6 +18,16 @@
package org.apache.commons.compress.archivers.zip;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeNotNull;
+import static org.junit.Assume.assumeTrue;
+
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -31,17 +41,7 @@
import java.util.Random;
import org.apache.commons.compress.AbstractTestCase;
-
import org.junit.Test;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeNotNull;
-import static org.junit.Assume.assumeTrue;
public class Zip64SupportIT {
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
index 0771bc4..8ff16a3 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipArchiveInputStreamTest.java
@@ -18,13 +18,14 @@
package org.apache.commons.compress.archivers.zip;
+import static org.junit.Assert.assertEquals;
+
import java.io.File;
import java.io.FileInputStream;
import java.net.URI;
import java.net.URL;
-import org.junit.Test;
-import static org.junit.Assert.assertEquals;
+import org.junit.Test;
public class ZipArchiveInputStreamTest {
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipEightByteIntegerTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipEightByteIntegerTest.java
index c71a21d..7f09083 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipEightByteIntegerTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipEightByteIntegerTest.java
@@ -19,6 +19,7 @@
package org.apache.commons.compress.archivers.zip;
import java.math.BigInteger;
+
import junit.framework.TestCase;
/**
diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
index 7047278..aeb14fb 100644
--- a/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
+++ b/src/test/java/org/apache/commons/compress/archivers/zip/ZipFileTest.java
@@ -26,6 +26,7 @@
import java.net.URL;
import java.util.ArrayList;
import java.util.Collections;
+
import junit.framework.TestCase;
public class ZipFileTest extends TestCase {
diff --git a/src/test/java/org/apache/commons/compress/compressors/BZip2UtilsTestCase.java b/src/test/java/org/apache/commons/compress/compressors/BZip2UtilsTestCase.java
index 17cf902..a745c4f 100644
--- a/src/test/java/org/apache/commons/compress/compressors/BZip2UtilsTestCase.java
+++ b/src/test/java/org/apache/commons/compress/compressors/BZip2UtilsTestCase.java
@@ -18,10 +18,10 @@
*/
package org.apache.commons.compress.compressors;
-import org.apache.commons.compress.compressors.bzip2.BZip2Utils;
-
import junit.framework.TestCase;
+import org.apache.commons.compress.compressors.bzip2.BZip2Utils;
+
public class BZip2UtilsTestCase extends TestCase {
public void testIsCompressedFilename() {
diff --git a/src/test/java/org/apache/commons/compress/compressors/GzipUtilsTestCase.java b/src/test/java/org/apache/commons/compress/compressors/GzipUtilsTestCase.java
index 83afdd3..5a8c86c 100644
--- a/src/test/java/org/apache/commons/compress/compressors/GzipUtilsTestCase.java
+++ b/src/test/java/org/apache/commons/compress/compressors/GzipUtilsTestCase.java
@@ -18,10 +18,10 @@
*/
package org.apache.commons.compress.compressors;
-import org.apache.commons.compress.compressors.gzip.GzipUtils;
-
import junit.framework.TestCase;
+import org.apache.commons.compress.compressors.gzip.GzipUtils;
+
public class GzipUtilsTestCase extends TestCase {
public void testIsCompressedFilename() {
diff --git a/src/test/java/org/apache/commons/compress/compressors/XZUtilsTestCase.java b/src/test/java/org/apache/commons/compress/compressors/XZUtilsTestCase.java
index c8c1fe3..24484be 100644
--- a/src/test/java/org/apache/commons/compress/compressors/XZUtilsTestCase.java
+++ b/src/test/java/org/apache/commons/compress/compressors/XZUtilsTestCase.java
@@ -18,10 +18,10 @@
*/
package org.apache.commons.compress.compressors;
-import org.apache.commons.compress.compressors.xz.XZUtils;
-
import junit.framework.TestCase;
+import org.apache.commons.compress.compressors.xz.XZUtils;
+
public class XZUtilsTestCase extends TestCase {
public void testIsCompressedFilename() {
diff --git a/src/test/java/org/apache/commons/compress/utils/CharsetsTest.java b/src/test/java/org/apache/commons/compress/utils/CharsetsTest.java
new file mode 100644
index 0000000..4447a02
--- /dev/null
+++ b/src/test/java/org/apache/commons/compress/utils/CharsetsTest.java
@@ -0,0 +1,71 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.commons.compress.utils;
+
+import java.nio.charset.Charset;
+
+import junit.framework.Assert;
+
+import org.junit.Test;
+
+/**
+ * Sanity checks for {@link Charsets}.
+ *
+ * @version $Id$
+ */
+public class CharsetsTest {
+
+ @Test
+ public void testToCharset() {
+ Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset((String) null));
+ Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset((Charset) null));
+ Assert.assertEquals(Charset.defaultCharset(), Charsets.toCharset(Charset.defaultCharset()));
+ Assert.assertEquals(Charset.forName("UTF-8"), Charsets.toCharset(Charset.forName("UTF-8")));
+ }
+
+ @Test
+ public void testIso8859_1() {
+ Assert.assertEquals("ISO-8859-1", Charsets.ISO_8859_1.name());
+ }
+
+ @Test
+ public void testUsAscii() {
+ Assert.assertEquals("US-ASCII", Charsets.US_ASCII.name());
+ }
+
+ @Test
+ public void testUtf16() {
+ Assert.assertEquals("UTF-16", Charsets.UTF_16.name());
+ }
+
+ @Test
+ public void testUtf16Be() {
+ Assert.assertEquals("UTF-16BE", Charsets.UTF_16BE.name());
+ }
+
+ @Test
+ public void testUtf16Le() {
+ Assert.assertEquals("UTF-16LE", Charsets.UTF_16LE.name());
+ }
+
+ @Test
+ public void testUtf8() {
+ Assert.assertEquals("UTF-8", Charsets.UTF_8.name());
+ }
+
+}
diff --git a/src/test/java/org/apache/commons/compress/utils/CountingStreamTest.java b/src/test/java/org/apache/commons/compress/utils/CountingStreamTest.java
index 8454147..82e06de 100644
--- a/src/test/java/org/apache/commons/compress/utils/CountingStreamTest.java
+++ b/src/test/java/org/apache/commons/compress/utils/CountingStreamTest.java
@@ -18,12 +18,14 @@
*/
package org.apache.commons.compress.utils;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import org.junit.Test;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+
+import org.junit.Test;
+
public class CountingStreamTest {
@Test