This is an automated email from the ASF dual-hosted git repository. ebourg pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-compress.git
commit a9ed0221c7b8d591048013cc317cfac9a60d0ab1 Author: Emmanuel Bourg <ebo...@apache.org> AuthorDate: Mon Jul 19 15:20:13 2021 +0200 Use static import for StandardCharsets --- .../archivers/ar/ArArchiveOutputStream.java | 5 +-- .../compress/archivers/sevenz/SevenZFile.java | 7 ++-- .../archivers/sevenz/SevenZOutputFile.java | 5 +-- .../archivers/tar/TarArchiveOutputStream.java | 9 ++--- .../commons/compress/archivers/tar/TarUtils.java | 5 ++- .../archivers/zip/AbstractUnicodeExtraField.java | 5 +-- .../compress/archivers/zip/ZipEncodingHelper.java | 7 ++-- .../gzip/GzipCompressorInputStream.java | 9 +++-- .../gzip/GzipCompressorOutputStream.java | 7 ++-- .../commons/compress/utils/ArchiveUtils.java | 11 +++--- .../commons/compress/archivers/TarTestCase.java | 4 +-- .../commons/compress/archivers/ZipTestCase.java | 4 +-- .../compress/archivers/examples/ExpanderTest.java | 19 +++++----- .../examples/ParameterizedArchiverTest.java | 9 ++--- .../examples/ParameterizedExpanderTest.java | 9 ++--- .../archivers/examples/SevenZArchiverTest.java | 9 ++--- .../compress/archivers/sevenz/SevenZFileTest.java | 22 ++++++------ .../archivers/tar/TarArchiveEntryTest.java | 4 +-- .../archivers/tar/TarArchiveOutputStreamTest.java | 24 ++++++------- .../archivers/tar/TarMemoryFileSystemTest.java | 8 ++--- .../compress/archivers/tar/TarUtilsTest.java | 40 +++++++++++----------- .../compress/archivers/zip/DataDescriptorTest.java | 8 ++--- .../compress/archivers/zip/NioZipEncodingTest.java | 29 ++++++++-------- .../compress/archivers/zip/UTF8ZipFilesTest.java | 19 +++++----- .../compress/archivers/zip/ZipFileTest.java | 22 ++++++------ .../CompressorStreamFactoryRoundtripTest.java | 5 +-- .../lz77support/LZ77CompressorTest.java | 8 ++--- .../BoundedSeekableByteChannelInputStreamTest.java | 6 ++-- .../utils/FixedLengthBlockOutputStreamTest.java | 6 ++-- .../MultiReadOnlySeekableByteChannelTest.java | 5 +-- .../utils/SeekableInMemoryByteChannelTest.java | 8 ++--- 31 files changed, 175 insertions(+), 163 deletions(-) diff --git a/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java b/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java index 96160b7..72eab02 100644 --- a/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java +++ b/src/main/java/org/apache/commons/compress/archivers/ar/ArArchiveOutputStream.java @@ -21,7 +21,6 @@ package org.apache.commons.compress.archivers.ar; import java.io.File; import java.io.IOException; import java.io.OutputStream; -import java.nio.charset.StandardCharsets; import java.nio.file.LinkOption; import java.nio.file.Path; @@ -29,6 +28,8 @@ import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.archivers.ArchiveOutputStream; import org.apache.commons.compress.utils.ArchiveUtils; +import static java.nio.charset.StandardCharsets.*; + /** * Implements the "ar" archive format as an output stream. * @@ -125,7 +126,7 @@ public class ArArchiveOutputStream extends ArchiveOutputStream { } private long write(final String data) throws IOException { - final byte[] bytes = data.getBytes(StandardCharsets.US_ASCII); + final byte[] bytes = data.getBytes(US_ASCII); write(bytes); return bytes.length; } diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java index 25a7483..5812648 100644 --- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZFile.java @@ -30,7 +30,6 @@ import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.CharBuffer; import java.nio.channels.SeekableByteChannel; -import java.nio.charset.StandardCharsets; import java.nio.charset.CharsetEncoder; import java.nio.file.Files; import java.nio.file.StandardOpenOption; @@ -52,6 +51,8 @@ import org.apache.commons.compress.utils.CRC32VerifyingInputStream; import org.apache.commons.compress.utils.IOUtils; import org.apache.commons.compress.utils.InputStreamStatistics; +import static java.nio.charset.StandardCharsets.*; + /** * Reads a 7z file, using SeekableByteChannel under * the covers. @@ -1400,7 +1401,7 @@ public class SevenZFile implements Closeable { for (int i = 0; i < namesLength; i += 2) { if (names[i] == 0 && names[i + 1] == 0) { checkEntryIsInitialized(fileMap, nextFile); - fileMap.get(nextFile).setName(new String(names, nextName, i - nextName, StandardCharsets.UTF_16LE)); + fileMap.get(nextFile).setName(new String(names, nextName, i - nextName, UTF_16LE)); nextName = i + 2; nextFile++; } @@ -2056,7 +2057,7 @@ public class SevenZFile implements Closeable { return lastSegment + "~"; } - private static final CharsetEncoder PASSWORD_ENCODER = StandardCharsets.UTF_16LE.newEncoder(); + private static final CharsetEncoder PASSWORD_ENCODER = UTF_16LE.newEncoder(); private static byte[] utf16Decode(final char[] chars) throws IOException { if (chars == null) { diff --git a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java index 21be436..b1ba333 100644 --- a/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java +++ b/src/main/java/org/apache/commons/compress/archivers/sevenz/SevenZOutputFile.java @@ -29,7 +29,6 @@ import java.io.OutputStream; import java.nio.ByteBuffer; import java.nio.ByteOrder; import java.nio.channels.SeekableByteChannel; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.LinkOption; import java.nio.file.OpenOption; @@ -49,6 +48,8 @@ import java.util.zip.CRC32; import org.apache.commons.compress.archivers.ArchiveEntry; import org.apache.commons.compress.utils.CountingOutputStream; +import static java.nio.charset.StandardCharsets.*; + /** * Writes a 7z file. * @since 1.6 @@ -626,7 +627,7 @@ public class SevenZOutputFile implements Closeable { final DataOutputStream out = new DataOutputStream(baos); out.write(0); for (final SevenZArchiveEntry entry : files) { - out.write(entry.getName().getBytes(StandardCharsets.UTF_16LE)); + out.write(entry.getName().getBytes(UTF_16LE)); out.writeShort(0); } out.flush(); 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 c0cbebb..18744c9 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 @@ -23,7 +23,6 @@ import java.io.IOException; import java.io.OutputStream; import java.io.StringWriter; import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; import java.nio.file.LinkOption; import java.nio.file.Path; import java.util.Arrays; @@ -38,6 +37,8 @@ import org.apache.commons.compress.archivers.zip.ZipEncodingHelper; import org.apache.commons.compress.utils.CountingOutputStream; import org.apache.commons.compress.utils.FixedLengthBlockOutputStream; +import static java.nio.charset.StandardCharsets.*; + /** * The TarOutputStream writes a UNIX tar archive as an OutputStream. Methods are provided to put * entries, and then write their contents by writing to this stream using write(). @@ -495,7 +496,7 @@ public class TarArchiveOutputStream extends ArchiveOutputStream { + 3 /* blank, equals and newline */ + 2 /* guess 9 < actual length < 100 */; String line = len + " " + key + "=" + value + "\n"; - int actualLength = line.getBytes(StandardCharsets.UTF_8).length; + int actualLength = line.getBytes(UTF_8).length; while (len != actualLength) { // Adjust for cases where length < 10 or > 100 // or where UTF-8 encoding isn't a single octet @@ -504,11 +505,11 @@ public class TarArchiveOutputStream extends ArchiveOutputStream { // first pass so we'd need a second. len = actualLength; line = len + " " + key + "=" + value + "\n"; - actualLength = line.getBytes(StandardCharsets.UTF_8).length; + actualLength = line.getBytes(UTF_8).length; } w.write(line); } - return w.toString().getBytes(StandardCharsets.UTF_8); + return w.toString().getBytes(UTF_8); } private String stripTo7Bits(final String name) { diff --git a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java index 4dd0f58..0b6bdd8 100644 --- a/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java +++ b/src/main/java/org/apache/commons/compress/archivers/tar/TarUtils.java @@ -23,7 +23,6 @@ import java.io.IOException; import java.io.InputStream; import java.math.BigInteger; import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.HashMap; @@ -35,6 +34,7 @@ import org.apache.commons.compress.archivers.zip.ZipEncodingHelper; import org.apache.commons.compress.utils.CharsetNames; import org.apache.commons.compress.utils.IOUtils; +import static java.nio.charset.StandardCharsets.*; import static org.apache.commons.compress.archivers.tar.TarConstants.CHKSUMLEN; import static org.apache.commons.compress.archivers.tar.TarConstants.CHKSUM_OFFSET; import static org.apache.commons.compress.archivers.tar.TarConstants.SPARSE_NUMBYTES_LEN; @@ -769,8 +769,7 @@ public class TarUtils { throw new IOException("Failed to read Paxheader." + "Value should end with a newline"); } - final String value = new String(rest, 0, - restLen - 1, StandardCharsets.UTF_8); + final String value = new String(rest, 0, restLen - 1, UTF_8); headers.put(keyword, value); // for 0.0 PAX Headers 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 36b8872..60dae9b 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 @@ -18,10 +18,11 @@ package org.apache.commons.compress.archivers.zip; -import java.nio.charset.StandardCharsets; import java.util.zip.CRC32; import java.util.zip.ZipException; +import static java.nio.charset.StandardCharsets.*; + /** * A common base class for Unicode extra information extra fields. * @NotThreadSafe @@ -51,7 +52,7 @@ public abstract class AbstractUnicodeExtraField implements ZipExtraField { crc32.update(bytes, off, len); nameCRC32 = crc32.getValue(); - unicodeName = text.getBytes(StandardCharsets.UTF_8); + unicodeName = text.getBytes(UTF_8); } /** 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 d03369e..207de56 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 @@ -20,9 +20,10 @@ package org.apache.commons.compress.archivers.zip; import java.nio.ByteBuffer; import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; import java.nio.charset.UnsupportedCharsetException; +import static java.nio.charset.StandardCharsets.*; + /** * Static helper functions for robustly encoding file names in zip files. */ @@ -73,10 +74,10 @@ public abstract class ZipEncodingHelper { // check platform's default encoding charsetName = Charset.defaultCharset().name(); } - if (StandardCharsets.UTF_8.name().equalsIgnoreCase(charsetName)) { + if (UTF_8.name().equalsIgnoreCase(charsetName)) { return true; } - for (final String alias : StandardCharsets.UTF_8.aliases()) { + for (final String alias : UTF_8.aliases()) { if (alias.equalsIgnoreCase(charsetName)) { return true; } diff --git a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java index 9a8c879..e46912b 100644 --- a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java +++ b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorInputStream.java @@ -25,7 +25,6 @@ import java.io.InputStream; import java.io.DataInput; import java.io.DataInputStream; import java.io.BufferedInputStream; -import java.nio.charset.StandardCharsets; import java.util.zip.DataFormatException; import java.util.zip.Deflater; import java.util.zip.Inflater; @@ -37,6 +36,8 @@ import org.apache.commons.compress.utils.CountingInputStream; import org.apache.commons.compress.utils.IOUtils; import org.apache.commons.compress.utils.InputStreamStatistics; +import static java.nio.charset.StandardCharsets.*; + /** * Input stream that decompresses .gz files. * @@ -238,14 +239,12 @@ public class GzipCompressorInputStream extends CompressorInputStream // Original file name if ((flg & FNAME) != 0) { - parameters.setFilename(new String(readToNull(inData), - StandardCharsets.ISO_8859_1)); + parameters.setFilename(new String(readToNull(inData), ISO_8859_1)); } // Comment if ((flg & FCOMMENT) != 0) { - parameters.setComment(new String(readToNull(inData), - StandardCharsets.ISO_8859_1)); + parameters.setComment(new String(readToNull(inData), ISO_8859_1)); } // Header "CRC16" which is actually a truncated CRC32 (which isn't diff --git a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStream.java b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStream.java index 5563bac..4b2b42a 100644 --- a/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStream.java +++ b/src/main/java/org/apache/commons/compress/compressors/gzip/GzipCompressorOutputStream.java @@ -22,7 +22,6 @@ import java.io.IOException; import java.io.OutputStream; import java.nio.ByteBuffer; import java.nio.ByteOrder; -import java.nio.charset.StandardCharsets; import java.util.zip.CRC32; import java.util.zip.Deflater; import java.util.zip.GZIPInputStream; @@ -30,6 +29,8 @@ import java.util.zip.GZIPOutputStream; import org.apache.commons.compress.compressors.CompressorOutputStream; +import static java.nio.charset.StandardCharsets.*; + /** * Compressed output stream using the gzip format. This implementation improves * over the standard {@link GZIPOutputStream} class by allowing @@ -111,12 +112,12 @@ public class GzipCompressorOutputStream extends CompressorOutputStream { out.write(buffer.array()); if (filename != null) { - out.write(filename.getBytes(StandardCharsets.ISO_8859_1)); + out.write(filename.getBytes(ISO_8859_1)); out.write(0); } if (comment != null) { - out.write(comment.getBytes(StandardCharsets.ISO_8859_1)); + out.write(comment.getBytes(ISO_8859_1)); out.write(0); } } diff --git a/src/main/java/org/apache/commons/compress/utils/ArchiveUtils.java b/src/main/java/org/apache/commons/compress/utils/ArchiveUtils.java index 72c857d..53a199d 100644 --- a/src/main/java/org/apache/commons/compress/utils/ArchiveUtils.java +++ b/src/main/java/org/apache/commons/compress/utils/ArchiveUtils.java @@ -18,11 +18,12 @@ package org.apache.commons.compress.utils; -import java.nio.charset.StandardCharsets; import java.util.Arrays; import org.apache.commons.compress.archivers.ArchiveEntry; +import static java.nio.charset.StandardCharsets.*; + /** * Generic Archive utilities */ @@ -72,7 +73,7 @@ public class ArchiveUtils { public static boolean matchAsciiBuffer( final String expected, final byte[] buffer, final int offset, final int length){ final byte[] buffer1; - buffer1 = expected.getBytes(StandardCharsets.US_ASCII); + buffer1 = expected.getBytes(US_ASCII); return isEqual(buffer1, 0, buffer1.length, buffer, offset, length, false); } @@ -95,7 +96,7 @@ public class ArchiveUtils { * @return the bytes */ public static byte[] toAsciiBytes(final String inputString){ - return inputString.getBytes(StandardCharsets.US_ASCII); + return inputString.getBytes(US_ASCII); } /** @@ -105,7 +106,7 @@ public class ArchiveUtils { * @return the bytes, interpreted as an Ascii string */ public static String toAsciiString(final byte[] inputBytes){ - return new String(inputBytes, StandardCharsets.US_ASCII); + return new String(inputBytes, US_ASCII); } /** @@ -117,7 +118,7 @@ public class ArchiveUtils { * @return the bytes, interpreted as an Ascii string */ public static String toAsciiString(final byte[] inputBytes, final int offset, final int length){ - return new String(inputBytes, offset, length, StandardCharsets.US_ASCII); + return new String(inputBytes, offset, length, US_ASCII); } /** 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 d75ef8f..b52a5d6 100644 --- a/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java +++ b/src/test/java/org/apache/commons/compress/archivers/TarTestCase.java @@ -24,7 +24,6 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.Arrays; import java.util.List; @@ -39,6 +38,7 @@ import org.apache.commons.compress.utils.CharsetNames; import org.apache.commons.compress.utils.IOUtils; import org.junit.Test; +import static java.nio.charset.StandardCharsets.*; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -71,7 +71,7 @@ public final class TarTestCase extends AbstractTestCase { @Test public void testTarArchiveLongNameCreation() throws Exception { final String name = "testdata/12345678901234567890123456789012345678901234567890123456789012345678901234567890123456.xml"; - final byte[] bytes = name.getBytes(StandardCharsets.UTF_8); + final byte[] bytes = name.getBytes(UTF_8); assertEquals(bytes.length, 99); final File output = new File(dir, "bla.tar"); diff --git a/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java b/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java index ec717a1..c63e984 100644 --- a/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java +++ b/src/test/java/org/apache/commons/compress/archivers/ZipTestCase.java @@ -18,6 +18,7 @@ */ package org.apache.commons.compress.archivers; +import static java.nio.charset.StandardCharsets.*; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -33,7 +34,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.nio.channels.Channels; import java.nio.channels.SeekableByteChannel; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; @@ -723,7 +723,7 @@ public final class ZipTestCase extends AbstractTestCase { try (SeekableByteChannel channel = ZipSplitReadOnlySeekableByteChannel.buildFromLastSplitSegment(lastFile); InputStream inputStream = Channels.newInputStream(channel); ZipArchiveInputStream splitInputStream = new ZipArchiveInputStream(inputStream, - StandardCharsets.UTF_8.toString(), true, false, true)) { + UTF_8.toString(), true, false, true)) { ArchiveEntry entry; final int filesNum = countNonDirectories(directoryToZip); diff --git a/src/test/java/org/apache/commons/compress/archivers/examples/ExpanderTest.java b/src/test/java/org/apache/commons/compress/archivers/examples/ExpanderTest.java index 3091f64..d1935ad 100644 --- a/src/test/java/org/apache/commons/compress/archivers/examples/ExpanderTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/examples/ExpanderTest.java @@ -25,7 +25,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.nio.channels.FileChannel; import java.nio.channels.SeekableByteChannel; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.StandardOpenOption; @@ -45,6 +44,8 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import static java.nio.charset.StandardCharsets.*; + public class ExpanderTest extends AbstractTestCase { @Rule @@ -171,10 +172,10 @@ public class ExpanderTest extends AbstractTestCase { aos.putArchiveEntry(aos.createArchiveEntry(dir, "a/b/c")); aos.closeArchiveEntry(); aos.putArchiveEntry(aos.createArchiveEntry(dummy, "a/b/d.txt")); - aos.write("Hello, world 1".getBytes(StandardCharsets.UTF_8)); + aos.write("Hello, world 1".getBytes(UTF_8)); aos.closeArchiveEntry(); aos.putArchiveEntry(aos.createArchiveEntry(dummy, "a/b/c/e.txt")); - aos.write("Hello, world 2".getBytes(StandardCharsets.UTF_8)); + aos.write("Hello, world 2".getBytes(UTF_8)); aos.closeArchiveEntry(); aos.finish(); } @@ -195,10 +196,10 @@ public class ExpanderTest extends AbstractTestCase { aos.putArchiveEntry(aos.createArchiveEntry(dir, "a/b/c")); aos.closeArchiveEntry(); aos.putArchiveEntry(aos.createArchiveEntry(dummy, "a/b/d.txt")); - aos.write("Hello, world 1".getBytes(StandardCharsets.UTF_8)); + aos.write("Hello, world 1".getBytes(UTF_8)); aos.closeArchiveEntry(); aos.putArchiveEntry(aos.createArchiveEntry(dummy, "a/b/c/e.txt")); - aos.write("Hello, world 2".getBytes(StandardCharsets.UTF_8)); + aos.write("Hello, world 2".getBytes(UTF_8)); aos.closeArchiveEntry(); aos.finish(); } @@ -219,10 +220,10 @@ public class ExpanderTest extends AbstractTestCase { aos.putArchiveEntry(aos.createArchiveEntry(dir, "a/b/c")); aos.closeArchiveEntry(); aos.putArchiveEntry(aos.createArchiveEntry(dummy, "a/b/d.txt")); - aos.write("Hello, world 1".getBytes(StandardCharsets.UTF_8)); + aos.write("Hello, world 1".getBytes(UTF_8)); aos.closeArchiveEntry(); aos.putArchiveEntry(aos.createArchiveEntry(dummy, "a/b/c/e.txt")); - aos.write("Hello, world 2".getBytes(StandardCharsets.UTF_8)); + aos.write("Hello, world 2".getBytes(UTF_8)); aos.closeArchiveEntry(); aos.finish(); } @@ -237,7 +238,7 @@ public class ExpanderTest extends AbstractTestCase { try (ArchiveOutputStream aos = ArchiveStreamFactory.DEFAULT .createArchiveOutputStream("zip", Files.newOutputStream(archive.toPath()))) { aos.putArchiveEntry(aos.createArchiveEntry(dummy, entry)); - aos.write("Hello, world 1".getBytes(StandardCharsets.UTF_8)); + aos.write("Hello, world 1".getBytes(UTF_8)); aos.closeArchiveEntry(); aos.finish(); } @@ -253,7 +254,7 @@ public class ExpanderTest extends AbstractTestCase { private void assertHelloWorld(final String fileName, final String suffix) throws IOException { Assert.assertTrue(fileName + " does not exist", new File(resultDir, fileName).isFile()); - final byte[] expected = ("Hello, world " + suffix).getBytes(StandardCharsets.UTF_8); + final byte[] expected = ("Hello, world " + suffix).getBytes(UTF_8); try (InputStream is = Files.newInputStream(new File(resultDir, fileName).toPath())) { final byte[] actual = IOUtils.toByteArray(is); Assert.assertArrayEquals(expected, actual); diff --git a/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedArchiverTest.java b/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedArchiverTest.java index 5ab7be9..7398cfe 100644 --- a/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedArchiverTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedArchiverTest.java @@ -25,7 +25,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.nio.channels.FileChannel; import java.nio.channels.SeekableByteChannel; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.StandardOpenOption; import java.util.Arrays; @@ -45,6 +44,8 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized.Parameters; import org.junit.runners.Parameterized; +import static java.nio.charset.StandardCharsets.*; + @RunWith(Parameterized.class) public class ParameterizedArchiverTest extends AbstractTestCase { @@ -74,10 +75,10 @@ public class ParameterizedArchiverTest extends AbstractTestCase { final File c = new File(dir, "a/b/c"); c.mkdirs(); try (OutputStream os = Files.newOutputStream(new File(dir, "a/b/d.txt").toPath())) { - os.write("Hello, world 1".getBytes(StandardCharsets.UTF_8)); + os.write("Hello, world 1".getBytes(UTF_8)); } try (OutputStream os = Files.newOutputStream(new File(dir, "a/b/c/e.txt").toPath())) { - os.write("Hello, world 2".getBytes(StandardCharsets.UTF_8)); + os.write("Hello, world 2".getBytes(UTF_8)); } target = new File(resultDir, "test." + format); } @@ -146,7 +147,7 @@ public class ParameterizedArchiverTest extends AbstractTestCase { Assert.assertNotNull(expectedName + " does not exists", entry); Assert.assertEquals(expectedName, entry.getName()); Assert.assertFalse(expectedName + " is a directory", entry.isDirectory()); - final byte[] expected = ("Hello, world " + suffix).getBytes(StandardCharsets.UTF_8); + final byte[] expected = ("Hello, world " + suffix).getBytes(UTF_8); final byte[] actual = IOUtils.toByteArray(is); Assert.assertArrayEquals(expected, actual); } diff --git a/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedExpanderTest.java b/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedExpanderTest.java index e66cb89..da52536 100644 --- a/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedExpanderTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/examples/ParameterizedExpanderTest.java @@ -25,7 +25,6 @@ import java.io.InputStream; import java.io.OutputStream; import java.nio.channels.FileChannel; import java.nio.channels.SeekableByteChannel; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.StandardOpenOption; import java.util.Arrays; @@ -44,6 +43,8 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized.Parameters; import org.junit.runners.Parameterized; +import static java.nio.charset.StandardCharsets.*; + @RunWith(Parameterized.class) public class ParameterizedExpanderTest extends AbstractTestCase { @@ -82,10 +83,10 @@ public class ParameterizedExpanderTest extends AbstractTestCase { aos.putArchiveEntry(aos.createArchiveEntry(dir, "a/b/c")); aos.closeArchiveEntry(); aos.putArchiveEntry(aos.createArchiveEntry(dummy, "a/b/d.txt")); - aos.write("Hello, world 1".getBytes(StandardCharsets.UTF_8)); + aos.write("Hello, world 1".getBytes(UTF_8)); aos.closeArchiveEntry(); aos.putArchiveEntry(aos.createArchiveEntry(dummy, "a/b/c/e.txt")); - aos.write("Hello, world 2".getBytes(StandardCharsets.UTF_8)); + aos.write("Hello, world 2".getBytes(UTF_8)); aos.closeArchiveEntry(); aos.finish(); } @@ -146,7 +147,7 @@ public class ParameterizedExpanderTest extends AbstractTestCase { private void assertHelloWorld(final String fileName, final String suffix) throws IOException { Assert.assertTrue(fileName + " does not exist", new File(resultDir, fileName).isFile()); - final byte[] expected = ("Hello, world " + suffix).getBytes(StandardCharsets.UTF_8); + final byte[] expected = ("Hello, world " + suffix).getBytes(UTF_8); try (InputStream is = Files.newInputStream(new File(resultDir, fileName).toPath())) { final byte[] actual = IOUtils.toByteArray(is); Assert.assertArrayEquals(expected, actual); diff --git a/src/test/java/org/apache/commons/compress/archivers/examples/SevenZArchiverTest.java b/src/test/java/org/apache/commons/compress/archivers/examples/SevenZArchiverTest.java index 97b00d6..f6ce4f3 100644 --- a/src/test/java/org/apache/commons/compress/archivers/examples/SevenZArchiverTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/examples/SevenZArchiverTest.java @@ -23,7 +23,6 @@ import java.io.IOException; import java.io.OutputStream; import java.nio.channels.FileChannel; import java.nio.channels.SeekableByteChannel; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.StandardOpenOption; @@ -36,6 +35,8 @@ import org.junit.Assert; import org.junit.Before; import org.junit.Test; +import static java.nio.charset.StandardCharsets.*; + public class SevenZArchiverTest extends AbstractTestCase { private File target; @@ -46,10 +47,10 @@ public class SevenZArchiverTest extends AbstractTestCase { final File c = new File(dir, "a/b/c"); c.mkdirs(); try (OutputStream os = Files.newOutputStream(new File(dir, "a/b/d.txt").toPath())) { - os.write("Hello, world 1".getBytes(StandardCharsets.UTF_8)); + os.write("Hello, world 1".getBytes(UTF_8)); } try (OutputStream os = Files.newOutputStream(new File(dir, "a/b/c/e.txt").toPath())) { - os.write("Hello, world 2".getBytes(StandardCharsets.UTF_8)); + os.write("Hello, world 2".getBytes(UTF_8)); } target = new File(resultDir, "test.7z"); } @@ -115,7 +116,7 @@ public class SevenZArchiverTest extends AbstractTestCase { Assert.assertNotNull(expectedName + " does not exists", entry); Assert.assertEquals(expectedName, entry.getName()); Assert.assertFalse(expectedName + " is a directory", entry.isDirectory()); - final byte[] expected = ("Hello, world " + suffix).getBytes(StandardCharsets.UTF_8); + final byte[] expected = ("Hello, world " + suffix).getBytes(UTF_8); final byte[] actual = new byte[expected.length]; Assert.assertEquals(actual.length, z.read(actual)); Assert.assertEquals(-1, z.read()); diff --git a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java index 16ddd78..c08adaf 100644 --- a/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/sevenz/SevenZFileTest.java @@ -17,6 +17,7 @@ */ package org.apache.commons.compress.archivers.sevenz; +import static java.nio.charset.StandardCharsets.*; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; @@ -30,7 +31,6 @@ import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; import java.io.InputStream; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.security.NoSuchAlgorithmException; @@ -160,7 +160,7 @@ public class SevenZFileTest extends AbstractTestCase { public void test7zDecryptUnarchive() throws Exception { if (isStrongCryptoAvailable()) { test7zUnarchive(getFile("bla.encrypted.7z"), SevenZMethod.LZMA, // stack LZMA + AES - "foo".getBytes(StandardCharsets.UTF_16LE)); + "foo".getBytes(UTF_16LE)); } } @@ -452,7 +452,7 @@ public class SevenZFileTest extends AbstractTestCase { assert (bytesRead >= 0); off += bytesRead; } - assertEquals(testTxtContents, new String(contents, StandardCharsets.UTF_8)); + assertEquals(testTxtContents, new String(contents, UTF_8)); break; } } @@ -506,7 +506,7 @@ public class SevenZFileTest extends AbstractTestCase { off += bytesRead; } assertEquals(SevenZMethod.LZMA2, entry.getContentMethods().iterator().next().getMethod()); - assertEquals(filesTxtContents, new String(contents, StandardCharsets.UTF_8)); + assertEquals(filesTxtContents, new String(contents, UTF_8)); break; } } @@ -525,7 +525,7 @@ public class SevenZFileTest extends AbstractTestCase { off += bytesRead; } assertEquals(SevenZMethod.LZMA2, nextEntry.getContentMethods().iterator().next().getMethod()); - assertEquals(testTxtContents, new String(contents, StandardCharsets.UTF_8)); + assertEquals(testTxtContents, new String(contents, UTF_8)); } } @@ -572,7 +572,7 @@ public class SevenZFileTest extends AbstractTestCase { off += bytesRead; } assertEquals(SevenZMethod.LZMA2, testTxtEntry.getContentMethods().iterator().next().getMethod()); - assertEquals(testTxtContents, new String(contents, StandardCharsets.UTF_8)); + assertEquals(testTxtContents, new String(contents, UTF_8)); } // then read the next entry using getNextEntry @@ -637,7 +637,7 @@ public class SevenZFileTest extends AbstractTestCase { off += bytesRead; } assertEquals(SevenZMethod.LZMA2, testTxtEntry.getContentMethods().iterator().next().getMethod()); - assertEquals(testTxtContents, new String(contents, StandardCharsets.UTF_8)); + assertEquals(testTxtContents, new String(contents, UTF_8)); } } } @@ -677,7 +677,7 @@ public class SevenZFileTest extends AbstractTestCase { off += bytesRead; } assertEquals(SevenZMethod.LZMA2, testTxtEntry.getContentMethods().iterator().next().getMethod()); - assertEquals(testTxtContents, new String(contents, StandardCharsets.UTF_8)); + assertEquals(testTxtContents, new String(contents, UTF_8)); } } } @@ -712,7 +712,7 @@ public class SevenZFileTest extends AbstractTestCase { final SevenZArchiveEntry entry = out.createArchiveEntry(inputFile.toFile(), "test.txt"); out.putArchiveEntry(entry); - out.write("Test".getBytes(StandardCharsets.UTF_8)); + out.write("Test".getBytes(UTF_8)); out.closeArchiveEntry(); Files.deleteIfExists(inputFile); @@ -788,7 +788,7 @@ public class SevenZFileTest extends AbstractTestCase { assert (bytesRead >= 0); off += bytesRead; } - assertEquals(TEST2_CONTENT, new String(contents, StandardCharsets.UTF_8)); + assertEquals(TEST2_CONTENT, new String(contents, UTF_8)); assertNull(sevenZFile.getNextEntry()); } @@ -803,7 +803,7 @@ public class SevenZFileTest extends AbstractTestCase { assert (bytesRead >= 0); off += bytesRead; } - assertEquals("Hello, world!\n", new String(contents, StandardCharsets.UTF_8)); + assertEquals("Hello, world!\n", new String(contents, UTF_8)); assertNull(sevenZFile.getNextEntry()); } } 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 c0b1e97..0f119d6 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 @@ -18,6 +18,7 @@ package org.apache.commons.compress.archivers.tar; +import static java.nio.charset.StandardCharsets.*; import static org.apache.commons.compress.AbstractTestCase.getFile; import static org.apache.commons.compress.AbstractTestCase.getPath; import static org.junit.Assert.assertEquals; @@ -32,7 +33,6 @@ import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.Arrays; import java.util.Collections; @@ -265,7 +265,7 @@ public class TarArchiveEntryTest implements TarConstants { "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" + "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" + "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000" + - "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000").getBytes(StandardCharsets.UTF_8); + "\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000").getBytes(UTF_8); new TarArchiveEntry(entryContent, ZipEncodingHelper.getZipEncoding(CharsetNames.ISO_8859_1), false, -1); } 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 da21346..8777367 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 @@ -18,6 +18,7 @@ package org.apache.commons.compress.archivers.tar; +import static java.nio.charset.StandardCharsets.*; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -33,7 +34,6 @@ import java.io.InputStream; import java.io.InputStreamReader; import java.io.OutputStream; import java.io.Reader; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.security.MessageDigest; import java.util.Calendar; @@ -147,7 +147,7 @@ public class TarArchiveOutputStreamTest extends AbstractTestCase { + TarConstants.MODELEN + TarConstants.UIDLEN + TarConstants.GIDLEN, 12, - StandardCharsets.UTF_8)); + UTF_8)); final TarArchiveInputStream tin = new TarArchiveInputStream(new ByteArrayInputStream(data)); final TarArchiveEntry e = tin.getNextTarEntry(); @@ -168,8 +168,8 @@ public class TarArchiveOutputStreamTest extends AbstractTestCase { + TarConstants.MODELEN + TarConstants.UIDLEN + TarConstants.GIDLEN, 12, - StandardCharsets.UTF_8)); - assertEquals("6 a=b\n", new String(data, 512, 6, StandardCharsets.UTF_8)); + UTF_8)); + assertEquals("6 a=b\n", new String(data, 512, 6, UTF_8)); } @Test @@ -185,10 +185,10 @@ public class TarArchiveOutputStreamTest extends AbstractTestCase { + TarConstants.MODELEN + TarConstants.UIDLEN + TarConstants.GIDLEN, 12, - StandardCharsets.UTF_8)); + UTF_8)); assertEquals("99 a=0123456789012345678901234567890123456789" + "01234567890123456789012345678901234567890123456789" - + "012\n", new String(data, 512, 99, StandardCharsets.UTF_8)); + + "012\n", new String(data, 512, 99, UTF_8)); } @Test @@ -204,10 +204,10 @@ public class TarArchiveOutputStreamTest extends AbstractTestCase { + TarConstants.MODELEN + TarConstants.UIDLEN + TarConstants.GIDLEN, 12, - StandardCharsets.UTF_8)); + UTF_8)); assertEquals("101 a=0123456789012345678901234567890123456789" + "01234567890123456789012345678901234567890123456789" - + "0123\n", new String(data, 512, 101, StandardCharsets.UTF_8)); + + "0123\n", new String(data, 512, 101, UTF_8)); } private byte[] writePaxHeader(final Map<String, String> m) throws Exception { @@ -242,7 +242,7 @@ public class TarArchiveOutputStreamTest extends AbstractTestCase { tos.closeArchiveEntry(); final byte[] data = bos.toByteArray(); assertEquals("160 path=" + n + "\n", - new String(data, 512, 160, StandardCharsets.UTF_8)); + new String(data, 512, 160, UTF_8)); final TarArchiveInputStream tin = new TarArchiveInputStream(new ByteArrayInputStream(data)); final TarArchiveEntry e = tin.getNextTarEntry(); @@ -301,7 +301,7 @@ public class TarArchiveOutputStreamTest extends AbstractTestCase { + TarConstants.UIDLEN + TarConstants.GIDLEN + TarConstants.SIZELEN, 12, - StandardCharsets.UTF_8)); + UTF_8)); final TarArchiveInputStream tin = new TarArchiveInputStream(new ByteArrayInputStream(data)); final TarArchiveEntry e = tin.getNextTarEntry(); @@ -344,7 +344,7 @@ public class TarArchiveOutputStreamTest extends AbstractTestCase { tos.close(); final byte[] data = bos.toByteArray(); assertEquals("11 path=" + n + "\n", - new String(data, 512, 11, StandardCharsets.UTF_8)); + new String(data, 512, 11, UTF_8)); final TarArchiveInputStream tin = new TarArchiveInputStream(new ByteArrayInputStream(data)); final TarArchiveEntry e = tin.getNextTarEntry(); @@ -367,7 +367,7 @@ public class TarArchiveOutputStreamTest extends AbstractTestCase { tos.close(); final byte[] data = bos.toByteArray(); assertEquals("15 linkpath=" + n + "\n", - new String(data, 512, 15, StandardCharsets.UTF_8)); + new String(data, 512, 15, UTF_8)); final TarArchiveInputStream tin = new TarArchiveInputStream(new ByteArrayInputStream(data)); final TarArchiveEntry e = tin.getNextTarEntry(); diff --git a/src/test/java/org/apache/commons/compress/archivers/tar/TarMemoryFileSystemTest.java b/src/test/java/org/apache/commons/compress/archivers/tar/TarMemoryFileSystemTest.java index 85445bd..f46b230 100644 --- a/src/test/java/org/apache/commons/compress/archivers/tar/TarMemoryFileSystemTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/tar/TarMemoryFileSystemTest.java @@ -28,13 +28,13 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.nio.charset.StandardCharsets; import java.nio.file.FileSystem; import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.attribute.GroupPrincipal; import java.nio.file.attribute.UserPrincipal; +import static java.nio.charset.StandardCharsets.*; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -44,7 +44,7 @@ public class TarMemoryFileSystemTest { public void tarFromMemoryFileSystem() throws IOException, ArchiveException { try (FileSystem fileSystem = MemoryFileSystemBuilder.newLinux().build()) { final Path p = fileSystem.getPath("test.txt"); - Files.write(p, "Test".getBytes(StandardCharsets.UTF_8)); + Files.write(p, "Test".getBytes(UTF_8)); final File f = File.createTempFile("commons-compress-memoryfs", ".tar"); try (final OutputStream out = Files.newOutputStream(f.toPath()); @@ -71,7 +71,7 @@ public class TarMemoryFileSystemTest { entry.setSize(content.length()); tarOut.putArchiveEntry(entry); - tarOut.write("Test".getBytes(StandardCharsets.UTF_8)); + tarOut.write("Test".getBytes(UTF_8)); tarOut.closeArchiveEntry(); assertTrue(Files.exists(p)); @@ -86,7 +86,7 @@ public class TarMemoryFileSystemTest { final String group = "compress"; try (FileSystem fileSystem = MemoryFileSystemBuilder.newLinux().addUser(user).addGroup(group).build()) { final Path source = fileSystem.getPath("original-file.txt"); - Files.write(source, "Test".getBytes(StandardCharsets.UTF_8)); + Files.write(source, "Test".getBytes(UTF_8)); Files.setAttribute(source, "posix:owner", (UserPrincipal) () -> user); Files.setAttribute(source, "posix:group", (GroupPrincipal) () -> group); 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 b2c9cf1..1ec7bb0 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 @@ -21,7 +21,6 @@ package org.apache.commons.compress.archivers.tar; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.ArrayList; import java.util.Collections; @@ -38,6 +37,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import static java.nio.charset.StandardCharsets.*; import static org.apache.commons.compress.AbstractTestCase.getFile; import static org.hamcrest.CoreMatchers.startsWith; import static org.junit.Assert.assertEquals; @@ -77,7 +77,7 @@ public class TarUtilsTest { final long MAX_OCTAL = 077777777777L; // Allowed 11 digits final long MAX_OCTAL_OVERFLOW = 0777777777777L; // in fact 12 for some implementations final String maxOctal = "777777777777"; // Maximum valid octal - buffer = maxOctal.getBytes(StandardCharsets.UTF_8); + buffer = maxOctal.getBytes(UTF_8); value = TarUtils.parseOctal(buffer,0, buffer.length); assertEquals(MAX_OCTAL_OVERFLOW, value); buffer[buffer.length - 1] = ' '; @@ -112,19 +112,19 @@ public class TarUtilsTest { fail("Expected IllegalArgumentException - should be at least 2 bytes long"); } catch (final IllegalArgumentException expected) { } - buffer = "abcdef ".getBytes(StandardCharsets.UTF_8); // Invalid input + buffer = "abcdef ".getBytes(UTF_8); // Invalid input try { TarUtils.parseOctal(buffer,0, buffer.length); fail("Expected IllegalArgumentException"); } catch (final IllegalArgumentException expected) { } - buffer = " 0 07 ".getBytes(StandardCharsets.UTF_8); // Invalid - embedded space + buffer = " 0 07 ".getBytes(UTF_8); // Invalid - embedded space try { TarUtils.parseOctal(buffer,0, buffer.length); fail("Expected IllegalArgumentException - embedded space"); } catch (final IllegalArgumentException expected) { } - buffer = " 0\00007 ".getBytes(StandardCharsets.UTF_8); // Invalid - embedded NUL + buffer = " 0\00007 ".getBytes(UTF_8); // Invalid - embedded NUL try { TarUtils.parseOctal(buffer,0, buffer.length); fail("Expected IllegalArgumentException - embedded NUL"); @@ -207,14 +207,14 @@ public class TarUtilsTest { public void testNegative() { final byte [] buffer = new byte[22]; TarUtils.formatUnsignedOctalString(-1, buffer, 0, buffer.length); - assertEquals("1777777777777777777777", new String(buffer, StandardCharsets.UTF_8)); + assertEquals("1777777777777777777777", new String(buffer, UTF_8)); } @Test public void testOverflow() { final 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, StandardCharsets.UTF_8)); + assertEquals("7777777", new String(buffer, UTF_8)); try { TarUtils.formatUnsignedOctalString(017777777L, buffer, 0, buffer.length); fail("Should have cause IllegalArgumentException"); @@ -415,7 +415,7 @@ public class TarUtilsTest { @Test public void readSimplePaxHeader() throws Exception { final Map<String, String> headers = TarUtils.parsePaxHeaders( - new ByteArrayInputStream("30 atime=1321711775.972059463\n".getBytes(StandardCharsets.UTF_8)), + new ByteArrayInputStream("30 atime=1321711775.972059463\n".getBytes(UTF_8)), null, new HashMap<>()); assertEquals(1, headers.size()); assertEquals("1321711775.972059463", headers.get("atime")); @@ -424,7 +424,7 @@ public class TarUtilsTest { @Test public void secondEntryWinsWhenPaxHeaderContainsDuplicateKey() throws Exception { final Map<String, String> headers = TarUtils.parsePaxHeaders(new ByteArrayInputStream("11 foo=bar\n11 foo=baz\n" - .getBytes(StandardCharsets.UTF_8)), null, new HashMap<>()); + .getBytes(UTF_8)), null, new HashMap<>()); assertEquals(1, headers.size()); assertEquals("baz", headers.get("foo")); } @@ -433,7 +433,7 @@ public class TarUtilsTest { public void paxHeaderEntryWithEmptyValueRemovesKey() throws Exception { final Map<String, String> headers = TarUtils .parsePaxHeaders(new ByteArrayInputStream("11 foo=bar\n7 foo=\n" - .getBytes(StandardCharsets.UTF_8)), null, new HashMap<>()); + .getBytes(UTF_8)), null, new HashMap<>()); assertEquals(0, headers.size()); } @@ -441,7 +441,7 @@ public class TarUtilsTest { public void readPaxHeaderWithEmbeddedNewline() throws Exception { final Map<String, String> headers = TarUtils .parsePaxHeaders(new ByteArrayInputStream("28 comment=line1\nline2\nand3\n" - .getBytes(StandardCharsets.UTF_8)), null, new HashMap<>()); + .getBytes(UTF_8)), null, new HashMap<>()); assertEquals(1, headers.size()); assertEquals("line1\nline2\nand3", headers.get("comment")); } @@ -450,9 +450,9 @@ public class TarUtilsTest { public void readNonAsciiPaxHeader() throws Exception { final String ae = "\u00e4"; final String line = "11 path="+ ae + "\n"; - assertEquals(11, line.getBytes(StandardCharsets.UTF_8).length); + assertEquals(11, line.getBytes(UTF_8).length); final Map<String, String> headers = TarUtils - .parsePaxHeaders(new ByteArrayInputStream(line.getBytes(StandardCharsets.UTF_8)), null, new HashMap<>()); + .parsePaxHeaders(new ByteArrayInputStream(line.getBytes(UTF_8)), null, new HashMap<>()); assertEquals(1, headers.size()); assertEquals(ae, headers.get("path")); } @@ -472,7 +472,7 @@ public class TarUtilsTest { thrown.expect(IOException.class); thrown.expectMessage(startsWith("Failed to read Paxheader")); TarUtils.parsePaxHeaders( - new ByteArrayInputStream("30 atime=1321711775.9720594634".getBytes(StandardCharsets.UTF_8)), + new ByteArrayInputStream("30 atime=1321711775.9720594634".getBytes(UTF_8)), null, Collections.emptyMap()); } @@ -482,7 +482,7 @@ public class TarUtilsTest { + "26 GNU.sparse.numbytes=10\n"; final List<TarArchiveStructSparse> sparseHeaders = new ArrayList<>(); TarUtils.parsePaxHeaders( - new ByteArrayInputStream(header.getBytes(StandardCharsets.UTF_8)), + new ByteArrayInputStream(header.getBytes(UTF_8)), sparseHeaders, Collections.emptyMap()); assertEquals(1, sparseHeaders.size()); assertEquals(0, sparseHeaders.get(0).getOffset()); @@ -495,7 +495,7 @@ public class TarUtilsTest { + "24 GNU.sparse.offset=10\n"; final List<TarArchiveStructSparse> sparseHeaders = new ArrayList<>(); TarUtils.parsePaxHeaders( - new ByteArrayInputStream(header.getBytes(StandardCharsets.UTF_8)), + new ByteArrayInputStream(header.getBytes(UTF_8)), sparseHeaders, Collections.emptyMap()); assertEquals(2, sparseHeaders.size()); assertEquals(0, sparseHeaders.get(0).getOffset()); @@ -511,7 +511,7 @@ public class TarUtilsTest { final String header = "23 GNU.sparse.offset=a\n" + "26 GNU.sparse.numbytes=10\n"; TarUtils.parsePaxHeaders( - new ByteArrayInputStream(header.getBytes(StandardCharsets.UTF_8)), + new ByteArrayInputStream(header.getBytes(UTF_8)), null, Collections.emptyMap()); } @@ -522,7 +522,7 @@ public class TarUtilsTest { final String header = "23 GNU.sparse.offset=0\n" + "26 GNU.sparse.numbytes=1a\n"; TarUtils.parsePaxHeaders( - new ByteArrayInputStream(header.getBytes(StandardCharsets.UTF_8)), + new ByteArrayInputStream(header.getBytes(UTF_8)), null, Collections.emptyMap()); } @@ -533,7 +533,7 @@ public class TarUtilsTest { final String header = "24 GNU.sparse.offset=-1\n" + "26 GNU.sparse.numbytes=10\n"; TarUtils.parsePaxHeaders( - new ByteArrayInputStream(header.getBytes(StandardCharsets.UTF_8)), + new ByteArrayInputStream(header.getBytes(UTF_8)), null, Collections.emptyMap()); } @@ -544,7 +544,7 @@ public class TarUtilsTest { final String header = "23 GNU.sparse.offset=0\n" + "26 GNU.sparse.numbytes=-1\n"; TarUtils.parsePaxHeaders( - new ByteArrayInputStream(header.getBytes(StandardCharsets.UTF_8)), + new ByteArrayInputStream(header.getBytes(UTF_8)), null, Collections.emptyMap()); } diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/DataDescriptorTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/DataDescriptorTest.java index d54de45..6c2f720 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/DataDescriptorTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/DataDescriptorTest.java @@ -22,7 +22,6 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.Arrays; @@ -31,6 +30,7 @@ import org.junit.After; import org.junit.Before; import org.junit.Test; +import static java.nio.charset.StandardCharsets.*; import static org.apache.commons.compress.AbstractTestCase.mkdir; import static org.apache.commons.compress.AbstractTestCase.rmdir; import static org.junit.Assert.assertArrayEquals; @@ -56,7 +56,7 @@ public class DataDescriptorTest { final ByteArrayOutputStream o = new ByteArrayOutputStream(); try (ZipArchiveOutputStream zos = new ZipArchiveOutputStream(o)) { zos.putArchiveEntry(new ZipArchiveEntry("test1.txt")); - zos.write("foo".getBytes(StandardCharsets.UTF_8)); + zos.write("foo".getBytes(UTF_8)); zos.closeArchiveEntry(); } final byte[] data = o.toByteArray(); @@ -96,7 +96,7 @@ public class DataDescriptorTest { final File f = new File(dir, "test.zip"); try (ZipArchiveOutputStream zos = new ZipArchiveOutputStream(f)) { zos.putArchiveEntry(new ZipArchiveEntry("test1.txt")); - zos.write("foo".getBytes(StandardCharsets.UTF_8)); + zos.write("foo".getBytes(UTF_8)); zos.closeArchiveEntry(); } @@ -138,7 +138,7 @@ public class DataDescriptorTest { final ByteArrayOutputStream init = new ByteArrayOutputStream(); try (ZipArchiveOutputStream zos = new ZipArchiveOutputStream(init)) { zos.putArchiveEntry(new ZipArchiveEntry("test1.txt")); - zos.write("foo".getBytes(StandardCharsets.UTF_8)); + zos.write("foo".getBytes(UTF_8)); zos.closeArchiveEntry(); } diff --git a/src/test/java/org/apache/commons/compress/archivers/zip/NioZipEncodingTest.java b/src/test/java/org/apache/commons/compress/archivers/zip/NioZipEncodingTest.java index 4a33917..19fd77b 100644 --- a/src/test/java/org/apache/commons/compress/archivers/zip/NioZipEncodingTest.java +++ b/src/test/java/org/apache/commons/compress/archivers/zip/NioZipEncodingTest.java @@ -20,75 +20,76 @@ package org.apache.commons.compress.archivers.zip; import java.nio.ByteBuffer; -import java.nio.charset.StandardCharsets; import java.util.Arrays; import org.junit.Assert; import org.junit.Test; +import static java.nio.charset.StandardCharsets.*; + public class NioZipEncodingTest { private static final String UMLAUTS = "\u00e4\u00f6\u00fc"; @Test public void umlautToUTF16BE() { - final NioZipEncoding e = new NioZipEncoding(StandardCharsets.UTF_16BE, false); + final NioZipEncoding e = new NioZipEncoding(UTF_16BE, false); final ByteBuffer bb = e.encode(UMLAUTS); final int off = bb.arrayOffset(); final byte[] result = Arrays.copyOfRange(bb.array(), off, off + bb.limit() - bb.position()); - Assert.assertArrayEquals(UMLAUTS.getBytes(StandardCharsets.UTF_16BE), result); + Assert.assertArrayEquals(UMLAUTS.getBytes(UTF_16BE), result); } @Test public void umlautToUTF8() { - final NioZipEncoding e = new NioZipEncoding(StandardCharsets.UTF_8, true); + final NioZipEncoding e = new NioZipEncoding(UTF_8, true); final ByteBuffer bb = e.encode("\u00e4\u00f6\u00fc"); final int off = bb.arrayOffset(); final byte[] result = Arrays.copyOfRange(bb.array(), off, off + bb.limit() - bb.position()); - Assert.assertArrayEquals(UMLAUTS.getBytes(StandardCharsets.UTF_8), result); + Assert.assertArrayEquals(UMLAUTS.getBytes(UTF_8), result); } @Test public void umlautToISO88591() { - final NioZipEncoding e = new NioZipEncoding(StandardCharsets.ISO_8859_1, true); + final NioZipEncoding e = new NioZipEncoding(ISO_8859_1, true); final ByteBuffer bb = e.encode("\u00e4\u00f6\u00fc"); final int off = bb.arrayOffset(); final byte[] result = Arrays.copyOfRange(bb.array(), off, off + bb.limit() - bb.position()); - Assert.assertArrayEquals(UMLAUTS.getBytes(StandardCharsets.ISO_8859_1), result); + Assert.assertArrayEquals(UMLAUTS.getBytes(ISO_8859_1), result); } @Test public void unmappableUmlauts() { - final NioZipEncoding e = new NioZipEncoding(StandardCharsets.US_ASCII, false); + final NioZipEncoding e = new NioZipEncoding(US_ASCII, false); final ByteBuffer bb = e.encode("\u00e4\u00f6\u00fc"); final int off = bb.arrayOffset(); final byte[] result = Arrays.copyOfRange(bb.array(), off, off + bb.limit() - bb.position()); - Assert.assertEquals("%U00E4%U00F6%U00FC", new String(result, StandardCharsets.US_ASCII)); + Assert.assertEquals("%U00E4%U00F6%U00FC", new String(result, US_ASCII)); } private static final String RAINBOW_EMOJI = "\ud83c\udf08"; @Test public void unmappableRainbowEmoji() { - final NioZipEncoding e = new NioZipEncoding(StandardCharsets.US_ASCII, false); + final NioZipEncoding e = new NioZipEncoding(US_ASCII, false); final ByteBuffer bb = e.encode(RAINBOW_EMOJI); final int off = bb.arrayOffset(); final byte[] result = Arrays.copyOfRange(bb.array(), off, off + bb.limit() - bb.position()); - Assert.assertEquals("%UD83C%UDF08", new String(result, StandardCharsets.US_ASCII)); + Assert.assertEquals("%UD83C%UDF08", new String(result, US_ASCII)); } @Test public void rainbowEmojiToSurrogatePairUTF16() { - final NioZipEncoding e = new NioZipEncoding(StandardCharsets.UTF_16BE, false); + final NioZipEncoding e = new NioZipEncoding(UTF_16BE, false); final ByteBuffer bb = e.encode(RAINBOW_EMOJI); final int off = bb.arrayOffset(); final byte[] result = Arrays.copyOfRange(bb.array(), off, off + bb.limit() - bb.position()); - Assert.assertArrayEquals(RAINBOW_EMOJI.getBytes(StandardCharsets.UTF_16BE), result); + Assert.assertArrayEquals(RAINBOW_EMOJI.getBytes(UTF_16BE), result); } @Test public void partialSurrogatePair() { - final NioZipEncoding e = new NioZipEncoding(StandardCharsets.US_ASCII, false); + final NioZipEncoding e = new NioZipEncoding(US_ASCII, false); final ByteBuffer bb = e.encode("\ud83c"); final int off = bb.arrayOffset(); final byte[] result = Arrays.copyOfRange(bb.array(), off, off + bb.limit() - bb.position()); 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 10bd0d7..64a09a3 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 @@ -18,6 +18,7 @@ package org.apache.commons.compress.archivers.zip; +import static java.nio.charset.StandardCharsets.*; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotSame; @@ -27,7 +28,6 @@ import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; import java.nio.charset.Charset; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.Enumeration; import java.util.zip.CRC32; @@ -133,8 +133,8 @@ public class UTF8ZipFilesTest extends AbstractTestCase { try { // fix for test fails on Windows with default charset that is not UTF-8 String encoding = null; - if (Charset.defaultCharset() != StandardCharsets.UTF_8) { - encoding = StandardCharsets.UTF_8.name(); + if (Charset.defaultCharset() != UTF_8) { + encoding = UTF_8.name(); } zf = new ZipFile(archive, encoding, true); @@ -166,8 +166,8 @@ public class UTF8ZipFilesTest extends AbstractTestCase { try { // fix for test fails on Windows with default charset that is not UTF-8 String encoding = null; - if (Charset.defaultCharset() != StandardCharsets.UTF_8) { - encoding = StandardCharsets.UTF_8.name(); + if (Charset.defaultCharset() != UTF_8) { + encoding = UTF_8.name(); } zi = new ZipArchiveInputStream(archive, encoding, true); @@ -313,7 +313,7 @@ public class UTF8ZipFilesTest extends AbstractTestCase { } zos.putArchiveEntry(ze); - zos.write("Hello, world!".getBytes(StandardCharsets.US_ASCII)); + zos.write("Hello, world!".getBytes(US_ASCII)); zos.closeArchiveEntry(); ze = new ZipArchiveEntry(EURO_FOR_DOLLAR_TXT); @@ -330,7 +330,7 @@ public class UTF8ZipFilesTest extends AbstractTestCase { } zos.putArchiveEntry(ze); - zos.write("Give me your money!".getBytes(StandardCharsets.US_ASCII)); + zos.write("Give me your money!".getBytes(US_ASCII)); zos.closeArchiveEntry(); ze = new ZipArchiveEntry(ASCII_TXT); @@ -348,7 +348,7 @@ public class UTF8ZipFilesTest extends AbstractTestCase { } zos.putArchiveEntry(ze); - zos.write("ascii".getBytes(StandardCharsets.US_ASCII)); + zos.write("ascii".getBytes(US_ASCII)); zos.closeArchiveEntry(); zos.finish(); @@ -407,8 +407,7 @@ public class UTF8ZipFilesTest extends AbstractTestCase { ne.limit() - ne.position()); assertEquals(crc.getValue(), ucpf.getNameCRC32()); - assertEquals(expectedName, new String(ucpf.getUnicodeName(), - StandardCharsets.UTF_8)); + assertEquals(expectedName, new String(ucpf.getUnicodeName(), UTF_8)); } } 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 8370c16..2109a8a 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 @@ -18,6 +18,7 @@ package org.apache.commons.compress.archivers.zip; +import static java.nio.charset.StandardCharsets.*; import static org.apache.commons.compress.AbstractTestCase.getFile; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; @@ -33,7 +34,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.nio.channels.SeekableByteChannel; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Paths; import java.util.ArrayList; @@ -489,14 +489,14 @@ public class ZipFileTest { inflatedEntry.setMethod(ZipEntry.DEFLATED); inflatedEntry.setAlignment(1024); zipOutput.putArchiveEntry(inflatedEntry); - zipOutput.write("Hello Deflated\n".getBytes(StandardCharsets.UTF_8)); + zipOutput.write("Hello Deflated\n".getBytes(UTF_8)); zipOutput.closeArchiveEntry(); final ZipArchiveEntry storedEntry = new ZipArchiveEntry("stored.txt"); storedEntry.setMethod(ZipEntry.STORED); storedEntry.setAlignment(1024); zipOutput.putArchiveEntry(storedEntry); - zipOutput.write("Hello Stored\n".getBytes(StandardCharsets.UTF_8)); + zipOutput.write("Hello Stored\n".getBytes(UTF_8)); zipOutput.closeArchiveEntry(); final ZipArchiveEntry storedEntry2 = new ZipArchiveEntry("stored2.txt"); @@ -504,14 +504,14 @@ public class ZipFileTest { storedEntry2.setAlignment(1024); storedEntry2.addExtraField(new ResourceAlignmentExtraField(1)); zipOutput.putArchiveEntry(storedEntry2); - zipOutput.write("Hello overload-alignment Stored\n".getBytes(StandardCharsets.UTF_8)); + zipOutput.write("Hello overload-alignment Stored\n".getBytes(UTF_8)); zipOutput.closeArchiveEntry(); final ZipArchiveEntry storedEntry3 = new ZipArchiveEntry("stored3.txt"); storedEntry3.setMethod(ZipEntry.STORED); storedEntry3.addExtraField(new ResourceAlignmentExtraField(1024)); zipOutput.putArchiveEntry(storedEntry3); - zipOutput.write("Hello copy-alignment Stored\n".getBytes(StandardCharsets.UTF_8)); + zipOutput.write("Hello copy-alignment Stored\n".getBytes(UTF_8)); zipOutput.closeArchiveEntry(); } @@ -530,7 +530,7 @@ public class ZipFileTest { assertFalse(inflatedAlignmentEx.allowMethodChange()); try (InputStream stream = zf.getInputStream(inflatedEntry)) { Assert.assertEquals("Hello Deflated\n", - new String(IOUtils.toByteArray(stream), StandardCharsets.UTF_8)); + new String(IOUtils.toByteArray(stream), UTF_8)); } final ZipArchiveEntry storedEntry = zf.getEntry("stored.txt"); final ResourceAlignmentExtraField storedAlignmentEx = @@ -543,7 +543,7 @@ public class ZipFileTest { assertFalse(storedAlignmentEx.allowMethodChange()); try (InputStream stream = zf.getInputStream(storedEntry)) { Assert.assertEquals("Hello Stored\n", - new String(IOUtils.toByteArray(stream), StandardCharsets.UTF_8)); + new String(IOUtils.toByteArray(stream), UTF_8)); } final ZipArchiveEntry storedEntry2 = zf.getEntry("stored2.txt"); @@ -557,7 +557,7 @@ public class ZipFileTest { assertFalse(stored2AlignmentEx.allowMethodChange()); try (InputStream stream = zf.getInputStream(storedEntry2)) { Assert.assertEquals("Hello overload-alignment Stored\n", - new String(IOUtils.toByteArray(stream), StandardCharsets.UTF_8)); + new String(IOUtils.toByteArray(stream), UTF_8)); } final ZipArchiveEntry storedEntry3 = zf.getEntry("stored3.txt"); @@ -571,7 +571,7 @@ public class ZipFileTest { assertFalse(stored3AlignmentEx.allowMethodChange()); try (InputStream stream = zf.getInputStream(storedEntry3)) { Assert.assertEquals("Hello copy-alignment Stored\n", - new String(IOUtils.toByteArray(stream), StandardCharsets.UTF_8)); + new String(IOUtils.toByteArray(stream), UTF_8)); } } } @@ -972,8 +972,8 @@ public class ZipFileTest { } private void assertFileEqualIgnoreEndOfLine(final File file1, final File file2) throws IOException { - final List<String> linesOfFile1 = Files.readAllLines(Paths.get(file1.getCanonicalPath()), StandardCharsets.UTF_8); - final List<String> linesOfFile2 = Files.readAllLines(Paths.get(file2.getCanonicalPath()), StandardCharsets.UTF_8); + final List<String> linesOfFile1 = Files.readAllLines(Paths.get(file1.getCanonicalPath()), UTF_8); + final List<String> linesOfFile2 = Files.readAllLines(Paths.get(file2.getCanonicalPath()), UTF_8); if(linesOfFile1.size() != linesOfFile2.size()) { fail("files not equal : " + file1.getName() + " , " + file2.getName()); diff --git a/src/test/java/org/apache/commons/compress/compressors/CompressorStreamFactoryRoundtripTest.java b/src/test/java/org/apache/commons/compress/compressors/CompressorStreamFactoryRoundtripTest.java index d9d4faf..987dbb6 100644 --- a/src/test/java/org/apache/commons/compress/compressors/CompressorStreamFactoryRoundtripTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/CompressorStreamFactoryRoundtripTest.java @@ -20,7 +20,6 @@ package org.apache.commons.compress.compressors; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; -import java.nio.charset.StandardCharsets; import org.apache.commons.compress.utils.IOUtils; import org.junit.Assert; @@ -29,6 +28,8 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; +import static java.nio.charset.StandardCharsets.*; + @RunWith(Parameterized.class) public class CompressorStreamFactoryRoundtripTest { @@ -60,7 +61,7 @@ public class CompressorStreamFactoryRoundtripTest { final CompressorOutputStream compressorOutputStream = factory.createCompressorOutputStream(compressorName, compressedOs); final String fixture = "The quick brown fox jumps over the lazy dog"; - compressorOutputStream.write(fixture.getBytes(StandardCharsets.UTF_8)); + compressorOutputStream.write(fixture.getBytes(UTF_8)); compressorOutputStream.flush(); compressorOutputStream.close(); final ByteArrayInputStream is = new ByteArrayInputStream(compressedOs.toByteArray()); diff --git a/src/test/java/org/apache/commons/compress/compressors/lz77support/LZ77CompressorTest.java b/src/test/java/org/apache/commons/compress/compressors/lz77support/LZ77CompressorTest.java index 2e4f3f7..92ff881 100644 --- a/src/test/java/org/apache/commons/compress/compressors/lz77support/LZ77CompressorTest.java +++ b/src/test/java/org/apache/commons/compress/compressors/lz77support/LZ77CompressorTest.java @@ -19,13 +19,13 @@ package org.apache.commons.compress.compressors.lz77support; import java.io.IOException; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import org.junit.Test; +import static java.nio.charset.StandardCharsets.*; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; @@ -38,7 +38,7 @@ public class LZ77CompressorTest { * Example from "An Explanation of the Deflate Algorithm" by "Antaeus Feldspar". * @see "http://zlib.net/feldspar.html" */ - BLA = "Blah blah blah blah blah!".getBytes(StandardCharsets.US_ASCII); + BLA = "Blah blah blah blah blah!".getBytes(US_ASCII); /* * Example from Wikipedia article about LZSS. @@ -57,7 +57,7 @@ public class LZ77CompressorTest { + "Do you like green eggs and ham?\n" + "\n" + "I do not like them, Sam-I-am.\n" - + "I do not like green eggs and ham.").getBytes(StandardCharsets.US_ASCII); + + "I do not like green eggs and ham.").getBytes(US_ASCII); ONE_TO_TEN = new byte[] { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }; } @@ -290,7 +290,7 @@ public class LZ77CompressorTest { } private static final void assertLiteralBlock(final String expectedContent, final LZ77Compressor.Block block) { - assertLiteralBlock(expectedContent.getBytes(StandardCharsets.US_ASCII), block); + assertLiteralBlock(expectedContent.getBytes(US_ASCII), block); } private static final void assertLiteralBlock(final byte[] expectedContent, final LZ77Compressor.Block block) { diff --git a/src/test/java/org/apache/commons/compress/utils/BoundedSeekableByteChannelInputStreamTest.java b/src/test/java/org/apache/commons/compress/utils/BoundedSeekableByteChannelInputStreamTest.java index 0c97b2d..9910a13 100644 --- a/src/test/java/org/apache/commons/compress/utils/BoundedSeekableByteChannelInputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/utils/BoundedSeekableByteChannelInputStreamTest.java @@ -20,8 +20,8 @@ package org.apache.commons.compress.utils; import org.junit.Test; import java.io.IOException; -import java.nio.charset.StandardCharsets; +import static java.nio.charset.StandardCharsets.*; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; @@ -31,11 +31,11 @@ public class BoundedSeekableByteChannelInputStreamTest { public void checkRestrictedRead() throws IOException { byte[] readContent; try (BoundedSeekableByteChannelInputStream input = new BoundedSeekableByteChannelInputStream(0, 5, - new SeekableInMemoryByteChannel("Hello World!".getBytes(StandardCharsets.UTF_8)))) { + new SeekableInMemoryByteChannel("Hello World!".getBytes(UTF_8)))) { readContent = IOUtils.toByteArray(input); } assertEquals(5, readContent.length); - assertArrayEquals("Hello".getBytes(StandardCharsets.UTF_8), readContent); + assertArrayEquals("Hello".getBytes(UTF_8), readContent); } } \ No newline at end of file diff --git a/src/test/java/org/apache/commons/compress/utils/FixedLengthBlockOutputStreamTest.java b/src/test/java/org/apache/commons/compress/utils/FixedLengthBlockOutputStreamTest.java index 93b5cf5..51b95b3 100644 --- a/src/test/java/org/apache/commons/compress/utils/FixedLengthBlockOutputStreamTest.java +++ b/src/test/java/org/apache/commons/compress/utils/FixedLengthBlockOutputStreamTest.java @@ -18,6 +18,7 @@ */ package org.apache.commons.compress.utils; +import static java.nio.charset.StandardCharsets.*; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.junit.Assert.assertEquals; @@ -33,7 +34,6 @@ import java.io.OutputStream; import java.nio.ByteBuffer; import java.nio.channels.ClosedChannelException; import java.nio.channels.WritableByteChannel; -import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; import java.util.concurrent.atomic.AtomicBoolean; @@ -253,7 +253,7 @@ public class FixedLengthBlockOutputStreamTest { private void testWriteAndPad(final int blockSize, final String text, final boolean doPartialWrite) throws IOException { final MockWritableByteChannel mock = new MockWritableByteChannel(blockSize, doPartialWrite); - final byte[] msg = text.getBytes(StandardCharsets.US_ASCII); + final byte[] msg = text.getBytes(US_ASCII); final ByteArrayOutputStream bos = mock.bos; try (FixedLengthBlockOutputStream out = new FixedLengthBlockOutputStream(mock, blockSize)) { @@ -267,7 +267,7 @@ public class FixedLengthBlockOutputStreamTest { private void testWriteAndPadToStream(final int blockSize, final String text, final boolean doPartialWrite) throws IOException { final MockOutputStream mock = new MockOutputStream(blockSize, doPartialWrite); - final byte[] msg = text.getBytes(StandardCharsets.US_ASCII); + final byte[] msg = text.getBytes(US_ASCII); final ByteArrayOutputStream bos = mock.bos; try (FixedLengthBlockOutputStream out = new FixedLengthBlockOutputStream(mock, blockSize)) { diff --git a/src/test/java/org/apache/commons/compress/utils/MultiReadOnlySeekableByteChannelTest.java b/src/test/java/org/apache/commons/compress/utils/MultiReadOnlySeekableByteChannelTest.java index b50d01d..2ce9cf4 100644 --- a/src/test/java/org/apache/commons/compress/utils/MultiReadOnlySeekableByteChannelTest.java +++ b/src/test/java/org/apache/commons/compress/utils/MultiReadOnlySeekableByteChannelTest.java @@ -23,7 +23,6 @@ import java.nio.ByteBuffer; import java.nio.channels.ClosedChannelException; import java.nio.channels.NonWritableChannelException; import java.nio.channels.SeekableByteChannel; -import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -34,6 +33,8 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; +import static java.nio.charset.StandardCharsets.*; + /** * Initially based on <a * href="https://github.com/frugalmechanic/fm-common/blob/master/jvm/src/test/scala/fm/common/TestMultiReadOnlySeekableByteChannel.scala">TestMultiReadOnlySeekableByteChannel.scala</a> @@ -86,7 +87,7 @@ public class MultiReadOnlySeekableByteChannelTest { @Test public void checkForString() throws IOException { check("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789" - .getBytes(StandardCharsets.UTF_8)); + .getBytes(UTF_8)); } @Test diff --git a/src/test/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannelTest.java b/src/test/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannelTest.java index e2bcf50..ca52de9 100644 --- a/src/test/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannelTest.java +++ b/src/test/java/org/apache/commons/compress/utils/SeekableInMemoryByteChannelTest.java @@ -25,16 +25,16 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.ClosedChannelException; import java.nio.channels.SeekableByteChannel; -import java.nio.charset.StandardCharsets; import java.util.Arrays; +import static java.nio.charset.StandardCharsets.*; import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; public class SeekableInMemoryByteChannelTest { - private final byte[] testData = "Some data".getBytes(StandardCharsets.UTF_8); + private final byte[] testData = "Some data".getBytes(UTF_8); @Test public void shouldReadContentsProperly() throws IOException { @@ -74,7 +74,7 @@ public class SeekableInMemoryByteChannelTest { final int readCount = c.read(readBuffer); //then assertEquals(4L, readCount); - assertEquals("data", new String(readBuffer.array(), StandardCharsets.UTF_8)); + assertEquals("data", new String(readBuffer.array(), UTF_8)); assertEquals(testData.length, c.position()); c.close(); } @@ -152,7 +152,7 @@ public class SeekableInMemoryByteChannelTest { c.truncate(4); //then final byte[] bytes = Arrays.copyOf(c.array(), (int) c.size()); - assertEquals("Some", new String(bytes, StandardCharsets.UTF_8)); + assertEquals("Some", new String(bytes, UTF_8)); c.close(); }