Skip to content

Commit 04b2773

Browse files
committed
Reuse Commons IO
1 parent 8c4ecf7 commit 04b2773

7 files changed

Lines changed: 21 additions & 188 deletions

File tree

pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@
5151
<groupId>commons-io</groupId>
5252
<artifactId>commons-io</artifactId>
5353
<version>2.14.0</version>
54-
<scope>test</scope>
5554
</dependency>
5655
<dependency>
5756
<groupId>org.apache.commons</groupId>

src/main/java/org/apache/commons/csv/CSVFormat.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
import java.util.Objects;
4949
import java.util.Set;
5050

51+
import org.apache.commons.io.IOUtils;
52+
5153
/**
5254
* Specifies the format of a CSV file for parsing and writing.
5355
*

src/main/java/org/apache/commons/csv/CSVParser.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
import java.util.stream.Stream;
4848
import java.util.stream.StreamSupport;
4949

50+
import org.apache.commons.io.function.Uncheck;
51+
5052
/**
5153
* Parses CSV files according to the specified format.
5254
*
@@ -144,11 +146,7 @@ class CSVRecordIterator implements Iterator<CSVRecord> {
144146
private CSVRecord current;
145147

146148
private CSVRecord getNextRecord() {
147-
try {
148-
return CSVParser.this.nextRecord();
149-
} catch (final IOException e) {
150-
throw new UncheckedIOException("Exception reading next record: " + e.toString(), e);
151-
}
149+
return Uncheck.get(CSVParser.this::nextRecord);
152150
}
153151

154152
@Override

src/main/java/org/apache/commons/csv/CSVPrinter.java

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,19 @@
7070
*/
7171
public final class CSVPrinter implements Flushable, Closeable {
7272

73+
/**
74+
* Throws the given throwable.
75+
*
76+
* @param <T> The throwable cast type.
77+
* @param throwable The throwable to rethrow.
78+
* @return nothing because we throw.
79+
* @throws T Always thrown.
80+
*/
81+
@SuppressWarnings("unchecked")
82+
private static <T extends Throwable> RuntimeException rethrow(final Throwable throwable) throws T {
83+
throw (T) throwable;
84+
}
85+
7386
/** The place that the values get written. */
7487
private final Appendable appendable;
7588

@@ -300,7 +313,7 @@ public synchronized void printRecord(final Stream<?> values) throws IOException
300313
try {
301314
print(t);
302315
} catch (final IOException e) {
303-
throw IOUtils.rethrow(e);
316+
throw rethrow(e);
304317
}
305318
});
306319
println();
@@ -489,7 +502,7 @@ public void printRecords(final Stream<?> values) throws IOException {
489502
try {
490503
printRecordObject(t);
491504
} catch (final IOException e) {
492-
throw IOUtils.rethrow(e);
505+
throw rethrow(e);
493506
}
494507
});
495508
}

src/main/java/org/apache/commons/csv/IOUtils.java

Lines changed: 0 additions & 147 deletions
This file was deleted.

src/test/java/org/apache/commons/csv/CSVPrinterTest.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
import java.util.stream.Stream;
6262

6363
import org.apache.commons.io.FileUtils;
64+
import org.apache.commons.io.IOUtils;
6465
import org.apache.commons.io.output.NullOutputStream;
6566
import org.apache.commons.lang3.StringUtils;
6667
import org.h2.tools.SimpleResultSet;

src/test/java/org/apache/commons/csv/IOUtilsTest.java

Lines changed: 0 additions & 33 deletions
This file was deleted.

0 commit comments

Comments
 (0)