Skip to content

Commit f3a416f

Browse files
committed
simplify usage of InputStream
1 parent eae0cb1 commit f3a416f

File tree

2 files changed

+6
-12
lines changed

2 files changed

+6
-12
lines changed

example/src/main/java/example/ExampleCsvCompression.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,10 @@
22

33
import static java.nio.charset.StandardCharsets.UTF_8;
44

5-
import java.io.BufferedInputStream;
65
import java.io.BufferedOutputStream;
76
import java.io.IOException;
8-
import java.io.InputStreamReader;
7+
import java.io.InputStream;
98
import java.io.OutputStreamWriter;
10-
import java.io.Reader;
119
import java.nio.file.Files;
1210
import java.nio.file.Path;
1311
import java.util.zip.GZIPInputStream;
@@ -51,10 +49,8 @@ private static void readCsvGzipped(final Path file) throws IOException {
5149
}
5250
}
5351

54-
private static Reader gzipReader(final Path file) throws IOException {
55-
final var bufIn = new BufferedInputStream(Files.newInputStream(file));
56-
final var gzipIn = new GZIPInputStream(bufIn);
57-
return new InputStreamReader(gzipIn, UTF_8);
52+
private static InputStream gzipReader(final Path file) throws IOException {
53+
return new GZIPInputStream(Files.newInputStream(file));
5854
}
5955

6056
}

example/src/main/java/example/ExampleCsvReaderWithClasspathInput.java

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@
22

33
import java.io.FileNotFoundException;
44
import java.io.IOException;
5-
import java.io.InputStreamReader;
6-
import java.io.Reader;
7-
import java.nio.charset.StandardCharsets;
5+
import java.io.InputStream;
86

97
import de.siegmar.fastcsv.reader.CsvReader;
108
import de.siegmar.fastcsv.reader.CsvRecord;
@@ -18,12 +16,12 @@ public static void main(final String[] args) throws IOException {
1816
}
1917
}
2018

21-
static Reader readFromClasspath(final String name) throws FileNotFoundException {
19+
static InputStream readFromClasspath(final String name) throws FileNotFoundException {
2220
final var in = ExampleCsvReaderWithClasspathInput.class.getResourceAsStream(name);
2321
if (in == null) {
2422
throw new FileNotFoundException("Resource not found on classpath: " + name);
2523
}
26-
return new InputStreamReader(in, StandardCharsets.UTF_8);
24+
return in;
2725
}
2826

2927
}

0 commit comments

Comments
 (0)