Skip to content

Commit c815d3e

Browse files
committed
refactor: simplify BOM handling in CsvReader #149
1 parent 18688cc commit c815d3e

File tree

2 files changed

+1
-26
lines changed

2 files changed

+1
-26
lines changed

lib/src/main/java/de/siegmar/fastcsv/reader/BomUtil.java

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package de.siegmar.fastcsv.reader;
22

33
import java.io.IOException;
4-
import java.io.InputStreamReader;
5-
import java.io.Reader;
6-
import java.nio.charset.Charset;
74
import java.nio.file.Files;
85
import java.nio.file.Path;
96
import java.nio.file.StandardOpenOption;
@@ -90,26 +87,4 @@ static Optional<BomHeader> detectCharset(final Path file)
9087
}
9188
}
9289

93-
/// Opens a Reader for the given file, skipping a BOM header if present.
94-
/// If no BOM header is present, the `defaultCharset` is used.
95-
///
96-
/// @param file the file to open a Reader for
97-
/// @param defaultCharset the default charset to use if no BOM header is present
98-
/// @return a Reader for the given file
99-
/// @throws IOException if an I/O error occurs opening the file
100-
static Reader openReader(final Path file, final Charset defaultCharset) throws IOException {
101-
final var bomHeader = detectCharset(file);
102-
final var in = Files.newInputStream(file);
103-
104-
// No BOM header found
105-
if (bomHeader.isEmpty()) {
106-
return new InputStreamReader(in, defaultCharset);
107-
}
108-
109-
// Return reader with skipped BOM header
110-
final int bomLength = bomHeader.get().getLength();
111-
in.skipNBytes(bomLength);
112-
return new InputStreamReader(in, bomHeader.get().getCharset());
113-
}
114-
11590
}

lib/src/main/java/de/siegmar/fastcsv/reader/CsvReader.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -970,7 +970,7 @@ public <T> CsvReader<T> build(final CsvCallbackHandler<T> callbackHandler,
970970
Objects.requireNonNull(charset, "charset must not be null");
971971

972972
final Reader reader = detectBomHeader
973-
? BomUtil.openReader(file, charset)
973+
? new BomInputStreamReader(Files.newInputStream(file), charset)
974974
: new InputStreamReader(Files.newInputStream(file), charset);
975975

976976
return build(callbackHandler, reader);

0 commit comments

Comments
 (0)