Repository: commons-io Updated Branches: refs/heads/master 9d432121e -> 5ea5c9624
replace usage of deprecated Charsets constants with StandardCharsets constants Project: http://git-wip-us.apache.org/repos/asf/commons-io/repo Commit: http://git-wip-us.apache.org/repos/asf/commons-io/commit/0c838a79 Tree: http://git-wip-us.apache.org/repos/asf/commons-io/tree/0c838a79 Diff: http://git-wip-us.apache.org/repos/asf/commons-io/diff/0c838a79 Branch: refs/heads/master Commit: 0c838a799ace7673e721bd29f0570097eb8f2925 Parents: 9d43212 Author: pascalschumacher <[email protected]> Authored: Thu Nov 10 00:19:14 2016 +0100 Committer: pascalschumacher <[email protected]> Committed: Thu Nov 10 00:19:14 2016 +0100 ---------------------------------------------------------------------- .../io/input/ReversedLinesFileReader.java | 8 +++---- .../org/apache/commons/io/CharsetsTestCase.java | 7 +----- .../org/apache/commons/io/DemuxTestCase.java | 4 ++-- .../org/apache/commons/io/IOUtilsTestCase.java | 24 ++++++++++---------- .../io/filefilter/FileFilterTestCase.java | 11 ++++----- .../commons/io/input/BOMInputStreamTest.java | 19 ++++++---------- .../org/apache/commons/io/input/TailerTest.java | 5 ++-- .../io/output/LockableFileWriterTest.java | 5 ++-- 8 files changed, 34 insertions(+), 49 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/commons-io/blob/0c838a79/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java ---------------------------------------------------------------------- diff --git a/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java b/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java index 7522d84..6dc2a46 100644 --- a/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java +++ b/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java @@ -23,6 +23,7 @@ import java.io.RandomAccessFile; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; import java.nio.charset.CharsetEncoder; +import java.nio.charset.StandardCharsets; import org.apache.commons.io.Charsets; @@ -91,7 +92,6 @@ public class ReversedLinesFileReader implements Closeable { * @throws IOException if an I/O error occurs * @since 2.3 */ - @SuppressWarnings("deprecation") // unavoidable until Java 7 public ReversedLinesFileReader(final File file, final int blockSize, final Charset encoding) throws IOException { this.blockSize = blockSize; this.encoding = encoding; @@ -103,7 +103,7 @@ public class ReversedLinesFileReader implements Closeable { if (maxBytesPerChar == 1f) { // all one byte encodings are no problem byteDecrement = 1; - } else if (charset == Charsets.UTF_8) { + } else if (charset == StandardCharsets.UTF_8) { // UTF-8 works fine out of the box, for multibyte sequences a second UTF-8 byte can never be a newline byte // http://en.wikipedia.org/wiki/UTF-8 byteDecrement = 1; @@ -114,11 +114,11 @@ public class ReversedLinesFileReader implements Closeable { charset == Charset.forName("gbk") || // Windows code page 936 (Simplified Chinese) charset == Charset.forName("x-windows-950")) { // Windows code page 950 (Traditional Chinese) byteDecrement = 1; - } else if (charset == Charsets.UTF_16BE || charset == Charsets.UTF_16LE) { + } else if (charset == StandardCharsets.UTF_16BE || charset == StandardCharsets.UTF_16LE) { // UTF-16 new line sequences are not allowed as second tuple of four byte sequences, // however byte order has to be specified byteDecrement = 2; - } else if (charset == Charsets.UTF_16) { + } else if (charset == StandardCharsets.UTF_16) { throw new UnsupportedEncodingException("For UTF-16, you need to specify the byte order (use UTF-16BE or " + "UTF-16LE)"); } else { http://git-wip-us.apache.org/repos/asf/commons-io/blob/0c838a79/src/test/java/org/apache/commons/io/CharsetsTestCase.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/io/CharsetsTestCase.java b/src/test/java/org/apache/commons/io/CharsetsTestCase.java index fc3a90e..539c7ed 100644 --- a/src/test/java/org/apache/commons/io/CharsetsTestCase.java +++ b/src/test/java/org/apache/commons/io/CharsetsTestCase.java @@ -28,6 +28,7 @@ import org.junit.Test; * * @version $Id: CharEncodingTest.java 1298985 2012-03-09 19:12:49Z ggregory $ */ +@SuppressWarnings("deprecation") // testing deprecated code public class CharsetsTestCase { @Test @@ -44,7 +45,6 @@ public class CharsetsTestCase { } @Test - @SuppressWarnings("deprecation") // unavoidable until Java 7 public void testIso8859_1() { Assert.assertEquals("ISO-8859-1", Charsets.ISO_8859_1.name()); } @@ -58,31 +58,26 @@ public class CharsetsTestCase { } @Test - @SuppressWarnings("deprecation") // unavoidable until Java 7 public void testUsAscii() { Assert.assertEquals("US-ASCII", Charsets.US_ASCII.name()); } @Test - @SuppressWarnings("deprecation") // unavoidable until Java 7 public void testUtf16() { Assert.assertEquals("UTF-16", Charsets.UTF_16.name()); } @Test - @SuppressWarnings("deprecation") // unavoidable until Java 7 public void testUtf16Be() { Assert.assertEquals("UTF-16BE", Charsets.UTF_16BE.name()); } @Test - @SuppressWarnings("deprecation") // unavoidable until Java 7 public void testUtf16Le() { Assert.assertEquals("UTF-16LE", Charsets.UTF_16LE.name()); } @Test - @SuppressWarnings("deprecation") // unavoidable until Java 7 public void testUtf8() { Assert.assertEquals("UTF-8", Charsets.UTF_8.name()); } http://git-wip-us.apache.org/repos/asf/commons-io/blob/0c838a79/src/test/java/org/apache/commons/io/DemuxTestCase.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/io/DemuxTestCase.java b/src/test/java/org/apache/commons/io/DemuxTestCase.java index cb3e394..952405c 100644 --- a/src/test/java/org/apache/commons/io/DemuxTestCase.java +++ b/src/test/java/org/apache/commons/io/DemuxTestCase.java @@ -22,6 +22,7 @@ import static org.junit.Assert.assertNotNull; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.io.OutputStream; +import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Random; @@ -49,13 +50,12 @@ public class DemuxTestCase { private final HashMap<String, ByteArrayOutputStream> m_outputMap = new HashMap<>(); private final HashMap<String, Thread> m_threadMap = new HashMap<>(); - @SuppressWarnings("deprecation") // unavoidable until Java 7 private String getOutput(final String threadName) { final ByteArrayOutputStream output = m_outputMap.get(threadName); assertNotNull("getOutput()", output); - return output.toString(Charsets.UTF_8); + return output.toString(StandardCharsets.UTF_8); } private String getInput(final String threadName) { http://git-wip-us.apache.org/repos/asf/commons-io/blob/0c838a79/src/test/java/org/apache/commons/io/IOUtilsTestCase.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/io/IOUtilsTestCase.java b/src/test/java/org/apache/commons/io/IOUtilsTestCase.java index 1c3cbeb..8c942f2 100644 --- a/src/test/java/org/apache/commons/io/IOUtilsTestCase.java +++ b/src/test/java/org/apache/commons/io/IOUtilsTestCase.java @@ -28,6 +28,7 @@ import java.net.*; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.nio.channels.Selector; +import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; @@ -212,26 +213,25 @@ public class IOUtilsTestCase extends FileBasedTestCase { } } - @SuppressWarnings("deprecation") // unavoidable until Java 7 @Test public void testContentEquals_InputStream_InputStream() throws Exception { { - final ByteArrayInputStream input1 = new ByteArrayInputStream("".getBytes(Charsets.UTF_8)); + final ByteArrayInputStream input1 = new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)); assertTrue(IOUtils.contentEquals(input1, input1)); } { - final ByteArrayInputStream input1 = new ByteArrayInputStream("ABC".getBytes(Charsets.UTF_8)); + final ByteArrayInputStream input1 = new ByteArrayInputStream("ABC".getBytes(StandardCharsets.UTF_8)); assertTrue(IOUtils.contentEquals(input1, input1)); } assertTrue(IOUtils - .contentEquals(new ByteArrayInputStream("".getBytes(Charsets.UTF_8)), new ByteArrayInputStream("".getBytes(Charsets.UTF_8)))); - assertTrue(IOUtils.contentEquals(new BufferedInputStream(new ByteArrayInputStream("".getBytes(Charsets.UTF_8))), new BufferedInputStream( - new ByteArrayInputStream("".getBytes(Charsets.UTF_8))))); - assertTrue(IOUtils.contentEquals(new ByteArrayInputStream("ABC".getBytes(Charsets.UTF_8)), - new ByteArrayInputStream("ABC".getBytes(Charsets.UTF_8)))); - assertFalse(IOUtils.contentEquals(new ByteArrayInputStream("ABCD".getBytes(Charsets.UTF_8)), - new ByteArrayInputStream("ABC".getBytes(Charsets.UTF_8)))); - assertFalse(IOUtils.contentEquals(new ByteArrayInputStream("ABC".getBytes(Charsets.UTF_8)), - new ByteArrayInputStream("ABCD".getBytes(Charsets.UTF_8)))); + .contentEquals(new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)), new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8)))); + assertTrue(IOUtils.contentEquals(new BufferedInputStream(new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8))), new BufferedInputStream( + new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8))))); + assertTrue(IOUtils.contentEquals(new ByteArrayInputStream("ABC".getBytes(StandardCharsets.UTF_8)), + new ByteArrayInputStream("ABC".getBytes(StandardCharsets.UTF_8)))); + assertFalse(IOUtils.contentEquals(new ByteArrayInputStream("ABCD".getBytes(StandardCharsets.UTF_8)), + new ByteArrayInputStream("ABC".getBytes(StandardCharsets.UTF_8)))); + assertFalse(IOUtils.contentEquals(new ByteArrayInputStream("ABC".getBytes(StandardCharsets.UTF_8)), + new ByteArrayInputStream("ABCD".getBytes(StandardCharsets.UTF_8)))); } @Test public void testContentEquals_Reader_Reader() throws Exception { http://git-wip-us.apache.org/repos/asf/commons-io/blob/0c838a79/src/test/java/org/apache/commons/io/filefilter/FileFilterTestCase.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/io/filefilter/FileFilterTestCase.java b/src/test/java/org/apache/commons/io/filefilter/FileFilterTestCase.java index cbde381..2451449 100644 --- a/src/test/java/org/apache/commons/io/filefilter/FileFilterTestCase.java +++ b/src/test/java/org/apache/commons/io/filefilter/FileFilterTestCase.java @@ -16,7 +16,6 @@ */ package org.apache.commons.io.filefilter; -import org.apache.commons.io.Charsets; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOCase; import org.apache.commons.io.IOUtils; @@ -27,6 +26,7 @@ import org.junit.Before; import org.junit.Test; import java.io.*; +import java.nio.charset.StandardCharsets; import java.util.*; import static org.junit.Assert.assertEquals; @@ -1156,7 +1156,6 @@ public class FileFilterTestCase extends FileBasedTestCase { //----------------------------------------------------------------------- - @SuppressWarnings("deprecation") // unavoidable until Java 7 @Test public void testMagicNumberFileFilterBytes() throws Exception { final byte[] classFileMagicNumber = @@ -1175,7 +1174,7 @@ public class FileFilterTestCase extends FileBasedTestCase { TestUtils.generateTestData(classFileAStream, (long) 32); classFileAStream.close(); - FileUtils.write(xmlFileB, xmlFileContent, Charsets.UTF_8); + FileUtils.write(xmlFileB, xmlFileContent, StandardCharsets.UTF_8); FileUtils.touch(emptyFile); IOFileFilter filter = new MagicNumberFileFilter(classFileMagicNumber); @@ -1236,7 +1235,6 @@ public class FileFilterTestCase extends FileBasedTestCase { assertFiltering(filter, dir, false); } - @SuppressWarnings("deprecation") // unavoidable until Java 7 @Test public void testMagicNumberFileFilterString() throws Exception { final byte[] classFileMagicNumber = @@ -1255,7 +1253,7 @@ public class FileFilterTestCase extends FileBasedTestCase { TestUtils.generateTestData(classFileAStream, (long) 32); classFileAStream.close(); - FileUtils.write(xmlFileB, xmlFileContent, Charsets.UTF_8); + FileUtils.write(xmlFileB, xmlFileContent, StandardCharsets.UTF_8); IOFileFilter filter = new MagicNumberFileFilter(xmlMagicNumber); @@ -1270,7 +1268,6 @@ public class FileFilterTestCase extends FileBasedTestCase { assertFiltering(filter, dir, false); } - @SuppressWarnings("deprecation") // unavoidable until Java 7 @Test public void testMagicNumberFileFilterStringOffset() throws Exception { final String tarMagicNumber = "ustar"; @@ -1283,7 +1280,7 @@ public class FileFilterTestCase extends FileBasedTestCase { final OutputStream tarFileAStream = FileUtils.openOutputStream(tarFileA); TestUtils.generateTestData(tarFileAStream, tarMagicNumberOffset); - IOUtils.write(tarMagicNumber, tarFileAStream, Charsets.UTF_8); + IOUtils.write(tarMagicNumber, tarFileAStream, StandardCharsets.UTF_8); tarFileAStream.close(); if (!randomFileB.getParentFile().exists()) { http://git-wip-us.apache.org/repos/asf/commons-io/blob/0c838a79/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java b/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java index 0286394..e04eb81 100644 --- a/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java +++ b/src/test/java/org/apache/commons/io/input/BOMInputStreamTest.java @@ -23,6 +23,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.Reader; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import org.apache.commons.io.ByteOrderMark; import org.apache.commons.io.Charsets; @@ -440,8 +441,7 @@ public class BOMInputStreamTest { @Test public void testReadWithBOMUtf16Be() throws Exception { - @SuppressWarnings("deprecation") // unavoidable until Java 7 - final byte[] data = "ABC".getBytes(Charsets.UTF_16BE); + final byte[] data = "ABC".getBytes(StandardCharsets.UTF_16BE); final BOMInputStream in = new BOMInputStream(createUtf16BeDataStream(data, true), ByteOrderMark.UTF_16BE); assertEquals(0, in.read()); assertEquals('A', in.read()); @@ -464,8 +464,7 @@ public class BOMInputStreamTest { @Test public void testReadWithBOMUtf16Le() throws Exception { - @SuppressWarnings("deprecation") // unavoidable until Java 7 - final byte[] data = "ABC".getBytes(Charsets.UTF_16LE); + final byte[] data = "ABC".getBytes(StandardCharsets.UTF_16LE); final BOMInputStream in = new BOMInputStream(createUtf16LeDataStream(data, true), ByteOrderMark.UTF_16LE); assertEquals('A', in.read()); assertEquals(0, in.read()); @@ -548,8 +547,7 @@ public class BOMInputStreamTest { @Test public void testReadWithBOMUtf8() throws Exception { - @SuppressWarnings("deprecation") // unavoidable until Java 7 - final byte[] data = "ABC".getBytes(Charsets.UTF_8); + final byte[] data = "ABC".getBytes(StandardCharsets.UTF_8); final BOMInputStream in = new BOMInputStream(createUtf8DataStream(data, true), ByteOrderMark.UTF_8); assertEquals('A', in.read()); assertEquals('B', in.read()); @@ -622,17 +620,15 @@ public class BOMInputStreamTest { } @Test - @SuppressWarnings("deprecation") // unavoidable until Java 7 public void testReadXmlWithBOMUtf16Be() throws Exception { - final byte[] data = "<?xml version=\"1.0\" encoding=\"UTF-16BE\"?><X/>".getBytes(Charsets.UTF_16BE); + final byte[] data = "<?xml version=\"1.0\" encoding=\"UTF-16BE\"?><X/>".getBytes(StandardCharsets.UTF_16BE); parseXml(new BOMInputStream(createUtf16BeDataStream(data, true), ByteOrderMark.UTF_16BE)); parseXml(createUtf16BeDataStream(data, true)); } @Test - @SuppressWarnings("deprecation") // unavoidable until Java 7 public void testReadXmlWithBOMUtf16Le() throws Exception { - final byte[] data = "<?xml version=\"1.0\" encoding=\"UTF-16LE\"?><X/>".getBytes(Charsets.UTF_16LE); + final byte[] data = "<?xml version=\"1.0\" encoding=\"UTF-16LE\"?><X/>".getBytes(StandardCharsets.UTF_16LE); parseXml(new BOMInputStream(createUtf16LeDataStream(data, true), ByteOrderMark.UTF_16LE)); parseXml(createUtf16LeDataStream(data, true)); } @@ -657,8 +653,7 @@ public class BOMInputStreamTest { @Test public void testReadXmlWithBOMUtf8() throws Exception { - @SuppressWarnings("deprecation") // unavoidable until Java 7 - final byte[] data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><X/>".getBytes(Charsets.UTF_8); + final byte[] data = "<?xml version=\"1.0\" encoding=\"UTF-8\"?><X/>".getBytes(StandardCharsets.UTF_8); parseXml(new BOMInputStream(createUtf8DataStream(data, true))); parseXml(createUtf8DataStream(data, true)); } http://git-wip-us.apache.org/repos/asf/commons-io/blob/0c838a79/src/test/java/org/apache/commons/io/input/TailerTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/io/input/TailerTest.java b/src/test/java/org/apache/commons/io/input/TailerTest.java index 603c199..c8f298d 100644 --- a/src/test/java/org/apache/commons/io/input/TailerTest.java +++ b/src/test/java/org/apache/commons/io/input/TailerTest.java @@ -18,13 +18,13 @@ package org.apache.commons.io.input; import java.io.*; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.Collections; import java.util.List; import java.util.concurrent.Executor; import java.util.concurrent.ScheduledThreadPoolExecutor; -import org.apache.commons.io.Charsets; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.io.testtools.FileBasedTestCase; @@ -110,7 +110,6 @@ public class TailerTest extends FileBasedTestCase { listener.clear(); } - @SuppressWarnings("deprecation") // unavoidable until Java 7 @Test public void testMultiByteBreak() throws Exception { System.out.println("testMultiByteBreak() Default charset: "+Charset.defaultCharset().displayName()); @@ -122,7 +121,7 @@ public class TailerTest extends FileBasedTestCase { final String osname = System.getProperty("os.name"); final boolean isWindows = osname.startsWith("Windows"); // Need to use UTF-8 to read & write the file otherwise it can be corrupted (depending on the default charset) - final Charset charsetUTF8 = Charsets.UTF_8; + final Charset charsetUTF8 = StandardCharsets.UTF_8; tailer = new Tailer(file, charsetUTF8, listener, delay, false, isWindows, 4096); final Thread thread = new Thread(tailer); thread.start(); http://git-wip-us.apache.org/repos/asf/commons-io/blob/0c838a79/src/test/java/org/apache/commons/io/output/LockableFileWriterTest.java ---------------------------------------------------------------------- diff --git a/src/test/java/org/apache/commons/io/output/LockableFileWriterTest.java b/src/test/java/org/apache/commons/io/output/LockableFileWriterTest.java index 2e24cce..d3efcb7 100644 --- a/src/test/java/org/apache/commons/io/output/LockableFileWriterTest.java +++ b/src/test/java/org/apache/commons/io/output/LockableFileWriterTest.java @@ -19,9 +19,9 @@ package org.apache.commons.io.output; import java.io.File; import java.io.IOException; import java.io.Writer; +import java.nio.charset.StandardCharsets; import java.nio.charset.UnsupportedCharsetException; -import org.apache.commons.io.Charsets; import org.apache.commons.io.FileUtils; import org.apache.commons.io.IOUtils; import org.apache.commons.io.testtools.FileBasedTestCase; @@ -109,7 +109,6 @@ public class LockableFileWriterTest extends FileBasedTestCase { } //----------------------------------------------------------------------- - @SuppressWarnings("deprecation") // unavoidable until Java 7 @Test public void testAlternateLockDir() throws IOException { LockableFileWriter lfw1 = null; LockableFileWriter lfw2 = null; @@ -121,7 +120,7 @@ public class LockableFileWriterTest extends FileBasedTestCase { // try to open a second writer try { - lfw2 = new LockableFileWriter(file, Charsets.UTF_8, true, altLockDir.getAbsolutePath()); + lfw2 = new LockableFileWriter(file, StandardCharsets.UTF_8, true, altLockDir.getAbsolutePath()); fail("Somehow able to open a locked file. "); } catch(final IOException ioe) { final String msg = ioe.getMessage();
