static BufferedReader of(Reader reader, LineDelimiter lineDelimiter, int bufferSize) { if (lineDelimiter == null) { return new BufferedReader(reader); } return new LineReader(reader, lineDelimiter, bufferSize); }
public LineDecoder(FileInput in, DecoderTask task) { this.charset = task.getCharset(); CharsetDecoder decoder = charset .newDecoder() .onMalformedInput(CodingErrorAction.REPLACE) // TODO configurable? .onUnmappableCharacter(CodingErrorAction.REPLACE); // TODO configurable? this.inputStream = new FileInputInputStream(in); this.reader = LineReader.of( new InputStreamReader(inputStream, decoder), task.getLineDelimiterRecognized().orElse(null), 256 ); }
private static List<String> readLines(String text, LineDelimiter lineDelimiter, int bufferSize) throws IOException { BufferedReader reader = LineReader.of(new StringReader(text), lineDelimiter, bufferSize); List<String> result = new ArrayList<>(); String line; while ((line = reader.readLine()) != null) { result.add(line); } return result; } }