Better internal API

This commit is contained in:
Gary Gregory 2024-09-14 20:45:33 -04:00
parent 14d31b0244
commit 8cbb558027
2 changed files with 8 additions and 9 deletions

View File

@ -2292,7 +2292,8 @@ public final class CSVFormat implements Serializable {
while (EOF != (c = bufferedReader.read())) { while (EOF != (c = bufferedReader.read())) {
builder.append((char) c); builder.append((char) c);
Arrays.fill(lookAheadBuffer, (char) 0); Arrays.fill(lookAheadBuffer, (char) 0);
final String test = builder.toString() + new String(bufferedReader.peek(lookAheadBuffer)); bufferedReader.peek(lookAheadBuffer);
final String test = builder.toString() + new String(lookAheadBuffer);
final boolean isDelimiterStart = isDelimiter((char) c, test, pos, delimArray, delimLength); final boolean isDelimiterStart = isDelimiter((char) c, test, pos, delimArray, delimLength);
final boolean isCr = c == Constants.CR; final boolean isCr = c == Constants.CR;
final boolean isLf = c == Constants.LF; final boolean isLf = c == Constants.LF;

View File

@ -124,21 +124,19 @@ final class ExtendedBufferedReader extends BufferedReader {
} }
/** /**
* Populates the buffer with the next {@code buf.length} characters in the * Populates the buffer with the next {@code buf.length} characters in the current reader without consuming them. The next call to {@link #read()} will
* current reader without consuming them. The next call to {@link #read()} will * still return the next value. This doesn't affect the line number or the last character.
* still return the next value. This doesn't affect the line number or the last
* character.
* *
* @param buf the buffer to fill for the look ahead. * @param buf the buffer to fill for the look ahead.
* @return the buffer itself * @return The number of characters peeked, or -1 if the end of the stream has been reached.
* @throws IOException If an I/O error occurs * @throws IOException If an I/O error occurs
*/ */
char[] peek(final char[] buf) throws IOException { int peek(final char[] buf) throws IOException {
final int n = buf.length; final int n = buf.length;
super.mark(n); super.mark(n);
super.read(buf, 0, n); final int c = super.read(buf, 0, n);
super.reset(); super.reset();
return buf; return c;
} }
@Override @Override