From 8cbb558027f07bcde0e9786ce84abdd3043b317a Mon Sep 17 00:00:00 2001 From: Gary Gregory Date: Sat, 14 Sep 2024 20:45:33 -0400 Subject: [PATCH] Better internal API --- .../java/org/apache/commons/csv/CSVFormat.java | 3 ++- .../apache/commons/csv/ExtendedBufferedReader.java | 14 ++++++-------- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java index 712d35e1..271f4652 100644 --- a/src/main/java/org/apache/commons/csv/CSVFormat.java +++ b/src/main/java/org/apache/commons/csv/CSVFormat.java @@ -2292,7 +2292,8 @@ public final class CSVFormat implements Serializable { while (EOF != (c = bufferedReader.read())) { builder.append((char) c); 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 isCr = c == Constants.CR; final boolean isLf = c == Constants.LF; diff --git a/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java b/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java index 9083e296..1c23e53e 100644 --- a/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java +++ b/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java @@ -124,21 +124,19 @@ final class ExtendedBufferedReader extends BufferedReader { } /** - * Populates the buffer with the next {@code buf.length} characters in the - * 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. + * Populates the buffer with the next {@code buf.length} characters in the 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. * * @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 */ - char[] peek(final char[] buf) throws IOException { + int peek(final char[] buf) throws IOException { final int n = buf.length; super.mark(n); - super.read(buf, 0, n); + final int c = super.read(buf, 0, n); super.reset(); - return buf; + return c; } @Override