This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git


The following commit(s) were added to refs/heads/master by this push:
     new 34686ed  Remove unused exceptions. Use try-with-resoruces. Clean ups. 
Formatting.
34686ed is described below

commit 34686ed175a04091e3082faadf0adf1d44510bd3
Author: Gary Gregory <garydgreg...@gmail.com>
AuthorDate: Wed Jul 22 15:20:28 2020 -0400

    Remove unused exceptions. Use try-with-resoruces.
    Clean ups. Formatting.
---
 .../commons/io/input/ReversedLinesFileReader.java  | 22 +++++++++++-----------
 .../apache/commons/io/input/BoundedReaderTest.java |  8 ++++----
 .../io/input/ObservableInputStreamTest.java        | 14 ++++++--------
 .../commons/io/input/ReaderInputStreamTest.java    | 17 ++++++++---------
 .../ReversedLinesFileReaderTestParamBlockSize.java |  4 +++-
 .../ReversedLinesFileReaderTestParamFile.java      | 10 +++++-----
 .../commons/io/input/SequenceReaderTest.java       |  3 +--
 .../io/input/SwappedDataInputStreamTest.java       | 20 ++++++++------------
 .../commons/io/input/XmlStreamReaderTest.java      |  8 ++++----
 9 files changed, 50 insertions(+), 56 deletions(-)

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 ed14d53..dbdd66d 100644
--- a/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java
+++ b/src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java
@@ -146,27 +146,27 @@ public class ReversedLinesFileReader implements Closeable 
{
             // 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;
-        } else if(charset == Charset.forName("Shift_JIS") || // Same as for 
UTF-8
-                // 
http://www.herongyang.com/Unicode/JIS-Shift-JIS-Encoding.html
-                charset == Charset.forName("windows-31j") || // Windows code 
page 932 (Japanese)
-                charset == Charset.forName("x-windows-949") || // Windows code 
page 949 (Korean)
-                charset == Charset.forName("gbk") || // Windows code page 936 
(Simplified Chinese)
-                charset == Charset.forName("x-windows-950")) { // Windows code 
page 950 (Traditional Chinese)
+        } else if (charset == Charset.forName("Shift_JIS") || // Same as for 
UTF-8
+        // http://www.herongyang.com/Unicode/JIS-Shift-JIS-Encoding.html
+            charset == Charset.forName("windows-31j") || // Windows code page 
932 (Japanese)
+            charset == Charset.forName("x-windows-949") || // Windows code 
page 949 (Korean)
+            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 == 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 == StandardCharsets.UTF_16) {
-            throw new UnsupportedEncodingException("For UTF-16, you need to 
specify the byte order (use UTF-16BE or " +
-                    "UTF-16LE)");
+            throw new UnsupportedEncodingException(
+                "For UTF-16, you need to specify the byte order (use UTF-16BE 
or " + "UTF-16LE)");
         } else {
-            throw new UnsupportedEncodingException("Encoding " + encoding + " 
is not supported yet (feel free to " +
-                    "submit a patch)");
+            throw new UnsupportedEncodingException(
+                "Encoding " + encoding + " is not supported yet (feel free to 
" + "submit a patch)");
         }
 
         // NOTE: The new line sequences are matched in the order given, so it 
is important that \r\n is BEFORE \n
-        newLineSequences = new byte[][] { "\r\n".getBytes(encoding), 
"\n".getBytes(encoding), "\r".getBytes(encoding) };
+        newLineSequences = new byte[][] {"\r\n".getBytes(encoding), 
"\n".getBytes(encoding), "\r".getBytes(encoding)};
 
         avoidNewlineSplitBufferSize = newLineSequences[0].length;
 
diff --git a/src/test/java/org/apache/commons/io/input/BoundedReaderTest.java 
b/src/test/java/org/apache/commons/io/input/BoundedReaderTest.java
index 9f806fb..09acdde 100644
--- a/src/test/java/org/apache/commons/io/input/BoundedReaderTest.java
+++ b/src/test/java/org/apache/commons/io/input/BoundedReaderTest.java
@@ -203,17 +203,17 @@ public class BoundedReaderTest {
     }
 
     @Test
-    public void testLineNumberReaderAndStringReaderLastLineEolYes() throws 
IOException {
+    public void testLineNumberReaderAndStringReaderLastLineEolYes() {
         assertTimeout(Duration.ofMillis(5000), () -> testLineNumberReader(new 
StringReader(STRING_END_EOL)));
     }
 
     @Test
-    public void testLineNumberReaderAndFileReaderLastLineEolNo() throws 
IOException {
+    public void testLineNumberReaderAndFileReaderLastLineEolNo() {
         assertTimeout(Duration.ofMillis(5000), () -> 
testLineNumberReaderAndFileReaderLastLine(STRING_END_NO_EOL));
     }
 
     @Test
-    public void testLineNumberReaderAndFileReaderLastLineEolYes() throws 
IOException {
+    public void testLineNumberReaderAndFileReaderLastLineEolYes() {
         assertTimeout(Duration.ofMillis(5000), () -> 
testLineNumberReaderAndFileReaderLastLine(STRING_END_EOL));
     }
 
@@ -231,7 +231,7 @@ public class BoundedReaderTest {
     }
 
     @Test
-    public void testReadBytesEOF() throws IOException {
+    public void testReadBytesEOF() {
         assertTimeout(Duration.ofMillis(5000), () -> {
             final BoundedReader mr = new BoundedReader(sr, 3);
             try (BufferedReader br = new BufferedReader(mr)) {
diff --git 
a/src/test/java/org/apache/commons/io/input/ObservableInputStreamTest.java 
b/src/test/java/org/apache/commons/io/input/ObservableInputStreamTest.java
index 2a06c1e..5fe9019 100644
--- a/src/test/java/org/apache/commons/io/input/ObservableInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/ObservableInputStreamTest.java
@@ -117,22 +117,20 @@ public class ObservableInputStreamTest {
                 if (result == -1) {
                     ois.close();
                     break;
-                } else {
-                    assertEquals(readBuffer, lko.buffer);
-                    assertEquals(0, lko.offset);
-                    assertEquals(readBuffer.length, lko.length);
                 }
+                assertEquals(readBuffer, lko.buffer);
+                assertEquals(0, lko.offset);
+                assertEquals(readBuffer.length, lko.length);
             } else {
                 final int res = Math.min(11, bais.available());
                 final int result = ois.read(readBuffer, 1, 11);
                 if (result == -1) {
                     ois.close();
                     break;
-                } else {
-                    assertEquals(readBuffer, lko.buffer);
-                    assertEquals(1, lko.offset);
-                    assertEquals(res, lko.length);
                 }
+                assertEquals(readBuffer, lko.buffer);
+                assertEquals(1, lko.offset);
+                assertEquals(res, lko.length);
             }
         }
     }
diff --git 
a/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java 
b/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
index 33fbc8c..eb7349c 100644
--- a/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
@@ -66,15 +66,14 @@ public class ReaderInputStreamTest {
             if (read == -1) {
                 assertEquals(offset, expected.length);
                 break;
-            } else {
-                assertTrue(read <= bufferLength);
-                while (read > 0) {
-                    assertTrue(offset < expected.length);
-                    assertEquals(expected[offset], buffer[bufferOffset]);
-                    offset++;
-                    bufferOffset++;
-                    read--;
-                }
+            }
+            assertTrue(read <= bufferLength);
+            while (read > 0) {
+                assertTrue(offset < expected.length);
+                assertEquals(expected[offset], buffer[bufferOffset]);
+                offset++;
+                bufferOffset++;
+                read--;
             }
         }
         in.close();
diff --git 
a/src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestParamBlockSize.java
 
b/src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestParamBlockSize.java
index 963674a..0446e20 100644
--- 
a/src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestParamBlockSize.java
+++ 
b/src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestParamBlockSize.java
@@ -71,7 +71,9 @@ public class ReversedLinesFileReaderTestParamBlockSize {
     @AfterEach
     public void closeReader() {
         try {
-            reversedLinesFileReader.close();
+            if (reversedLinesFileReader != null) {
+                reversedLinesFileReader.close();
+            }
         } catch (final Exception e) {
             // ignore
         }
diff --git 
a/src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestParamFile.java
 
b/src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestParamFile.java
index 2258afc..1726f80 100644
--- 
a/src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestParamFile.java
+++ 
b/src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestParamFile.java
@@ -36,6 +36,7 @@ import org.junit.jupiter.params.provider.MethodSource;
  * Test checks symmetric behavior with  BufferedReader
  */
 public class ReversedLinesFileReaderTestParamFile {
+
     public static Stream<Arguments> testDataIntegrityWithBufferedReader() {
         return Stream.of(
                 Arguments.of("test-file-20byteslength.bin", "ISO_8859_1", 
null, false),
@@ -61,9 +62,8 @@ public class ReversedLinesFileReaderTestParamFile {
 
     @ParameterizedTest(name = "{0}, encoding={1}, blockSize={2}, 
useNonDefaultFileSystem={3}")
     @MethodSource
-    public void testDataIntegrityWithBufferedReader
-            (final String fileName, final String encodingName, final Integer 
blockSize, final boolean useNonDefaultFileSystem)
-            throws IOException, URISyntaxException {
+    public void testDataIntegrityWithBufferedReader(final String fileName, 
final String encodingName,
+        final Integer blockSize, final boolean useNonDefaultFileSystem) throws 
IOException, URISyntaxException {
 
         Path file = Paths.get(getClass().getResource("/" + fileName).toURI());
         FileSystem fileSystem = null;
@@ -74,8 +74,8 @@ public class ReversedLinesFileReaderTestParamFile {
 
         Charset encoding = Charset.forName(encodingName);
         try (ReversedLinesFileReader reversedLinesFileReader = blockSize == 
null
-                ? new ReversedLinesFileReader(file, encoding)
-                : new ReversedLinesFileReader(file, blockSize, encoding)) {
+            ? new ReversedLinesFileReader(file, encoding)
+            : new ReversedLinesFileReader(file, blockSize, encoding)) {
 
             final Stack<String> lineStack = new Stack<>();
             String line;
diff --git a/src/test/java/org/apache/commons/io/input/SequenceReaderTest.java 
b/src/test/java/org/apache/commons/io/input/SequenceReaderTest.java
index 3a405d8..7a73a34 100644
--- a/src/test/java/org/apache/commons/io/input/SequenceReaderTest.java
+++ b/src/test/java/org/apache/commons/io/input/SequenceReaderTest.java
@@ -17,9 +17,8 @@
 package org.apache.commons.io.input;
 
 import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertThrows;
 import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertThrows;
 
 import java.io.IOException;
 import java.io.Reader;
diff --git 
a/src/test/java/org/apache/commons/io/input/SwappedDataInputStreamTest.java 
b/src/test/java/org/apache/commons/io/input/SwappedDataInputStreamTest.java
index 072be05..634bc7c 100644
--- a/src/test/java/org/apache/commons/io/input/SwappedDataInputStreamTest.java
+++ b/src/test/java/org/apache/commons/io/input/SwappedDataInputStreamTest.java
@@ -62,17 +62,13 @@ public class SwappedDataInputStreamTest {
 
     @Test
     public void testReadBoolean() throws IOException {
-        bytes = new byte[] {
-            0x00,
-            0x01,
-            0x02,
-        };
-        final ByteArrayInputStream bais = new ByteArrayInputStream( bytes );
-        final SwappedDataInputStream sdis = new SwappedDataInputStream( bais );
-        assertEquals( false, sdis.readBoolean() );
-        assertEquals( true, sdis.readBoolean() );
-        assertEquals( true, sdis.readBoolean() );
-        sdis.close();
+        bytes = new byte[] {0x00, 0x01, 0x02,};
+        try (final ByteArrayInputStream bais = new 
ByteArrayInputStream(bytes)) {
+            final SwappedDataInputStream sdis = new 
SwappedDataInputStream(bais);
+            assertEquals(false, sdis.readBoolean());
+            assertEquals(true, sdis.readBoolean());
+            assertEquals(true, sdis.readBoolean());
+        }
     }
 
     @Test
@@ -136,7 +132,7 @@ public class SwappedDataInputStreamTest {
     }
 
     @Test
-    public void testReadUTF() throws IOException {
+    public void testReadUTF() {
         assertThrows(UnsupportedOperationException.class, () ->  
this.sdis.readUTF(),
                 "readUTF should be unsupported. ");
     }
diff --git a/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java 
b/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java
index 443e5ce..561b8d4 100644
--- a/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java
+++ b/src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java
@@ -83,22 +83,22 @@ public class XmlStreamReaderTest {
     }
 
     @Test
-    protected void testNullFileInput() throws IOException {
+    protected void testNullFileInput() {
         assertThrows(NullPointerException.class, () -> new 
XmlStreamReader((File)null));
     }
 
     @Test
-    protected void testNullInputStreamInput() throws IOException {
+    protected void testNullInputStreamInput() {
         assertThrows(NullPointerException.class, () -> new 
XmlStreamReader((InputStream) null));
     }
 
     @Test
-    protected void testNullURLInput() throws IOException {
+    protected void testNullURLInput() {
          assertThrows(NullPointerException.class, () -> new 
XmlStreamReader((URL)null));
     }
 
     @Test
-    protected void testNullURLConnectionInput() throws IOException {
+    protected void testNullURLConnectionInput() {
           assertThrows(NullPointerException.class, () -> new 
XmlStreamReader((URLConnection)null, "US-ASCII"));
     }
 

Reply via email to