Remove unused exceptions. Use try-with-resoruces.
Clean ups. Formatting.
MODIFY
src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java
src/main/java/org/apache/commons/io/input/ReversedLinesFileReader.java
@@ -158,11 +158,11 @@ public ReversedLinesFileReader(final Path file, final int blockSize, final Chars
// 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

MODIFY
src/test/java/org/apache/commons/io/input/BoundedReaderTest.java
src/test/java/org/apache/commons/io/input/BoundedReaderTest.java
@@ -203,17 +203,17 @@ public void testLineNumberReaderAndStringReaderLastLineEolNo() {
}
@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 void testLineNumberReaderAndFileReaderLastLine(final String data) throws
}
@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)) {

MODIFY
src/test/java/org/apache/commons/io/input/ObservableInputStreamTest.java
src/test/java/org/apache/commons/io/input/ObservableInputStreamTest.java
@@ -117,24 +117,22 @@ public void testDataBytesCalled() throws Exception {
if (result == -1) {
ois.close();
break;
- } else {
+ }
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);
}
}
}
- }
}

MODIFY
src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
src/test/java/org/apache/commons/io/input/ReaderInputStreamTest.java
@@ -66,7 +66,7 @@ private void testWithBufferedRead(final String testString, final String charsetN
if (read == -1) {
assertEquals(offset, expected.length);
break;
- } else {
+ }
assertTrue(read <= bufferLength);
while (read > 0) {
assertTrue(offset < expected.length);
@@ -76,7 +76,6 @@ private void testWithBufferedRead(final String testString, final String charsetN
read--;
}
}
- }
in.close();
}

MODIFY
src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestParamBlockSize.java
src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestParamBlockSize.java
@@ -71,7 +71,9 @@ public static IntStream blockSizes() {
@AfterEach
public void closeReader() {
try {
+ if (reversedLinesFileReader != null) {
reversedLinesFileReader.close();
+ }
} catch (final Exception e) {
// ignore
}

MODIFY
src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestParamFile.java
src/test/java/org/apache/commons/io/input/ReversedLinesFileReaderTestParamFile.java
* 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),
@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;

MODIFY
src/test/java/org/apache/commons/io/input/SequenceReaderTest.java
src/test/java/org/apache/commons/io/input/SequenceReaderTest.java
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;

MODIFY
src/test/java/org/apache/commons/io/input/SwappedDataInputStreamTest.java
src/test/java/org/apache/commons/io/input/SwappedDataInputStreamTest.java
@@ -62,17 +62,13 @@ public void tearDown() {
@Test
public void testReadBoolean() throws IOException {
- bytes = new byte[] {
- 0x00,
- 0x01,
- 0x02,
- };
- final ByteArrayInputStream bais = new ByteArrayInputStream( bytes );
+ 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());
- sdis.close();
+ }
}
@Test
@@ -136,7 +132,7 @@ public void testReadUnsignedShort() throws IOException {
}
@Test
- public void testReadUTF() throws IOException {
+ public void testReadUTF() {
assertThrows(UnsupportedOperationException.class, () -> this.sdis.readUTF(),
"readUTF should be unsupported. ");
}

MODIFY
src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java
src/test/java/org/apache/commons/io/input/XmlStreamReaderTest.java
@@ -83,22 +83,22 @@ protected void _testRawNoBomInvalid(final String encoding) throws Exception {
}
@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"));
}

Remove unused exceptions. Use try-with-resoruces.
Clean ups. Formatting.