This is an automated email from the ASF dual-hosted git repository. ggregory pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/commons-csv.git
commit 14d31b0244741cc453f7bb6a611ad20f56a77dd1 Author: Gary Gregory <garydgreg...@gmail.com> AuthorDate: Sat Sep 14 19:09:02 2024 -0400 Rename internal methods --- .../java/org/apache/commons/csv/CSVFormat.java | 2 +- .../apache/commons/csv/ExtendedBufferedReader.java | 10 ++++---- src/main/java/org/apache/commons/csv/Lexer.java | 12 ++++----- .../commons/csv/ExtendedBufferedReaderTest.java | 30 +++++++++++----------- 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/apache/commons/csv/CSVFormat.java b/src/main/java/org/apache/commons/csv/CSVFormat.java index 6c7317f2..712d35e1 100644 --- a/src/main/java/org/apache/commons/csv/CSVFormat.java +++ b/src/main/java/org/apache/commons/csv/CSVFormat.java @@ -2292,7 +2292,7 @@ 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.lookAhead(lookAheadBuffer)); + final String test = builder.toString() + new String(bufferedReader.peek(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 fc67449f..9083e296 100644 --- a/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java +++ b/src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java @@ -84,7 +84,7 @@ final class ExtendedBufferedReader extends BufferedReader { /** * Returns the last character that was read as an integer (0 to 65535). This will be the last character returned by - * any of the read methods. This will not include a character read using the {@link #lookAhead()} method. If no + * any of the read methods. This will not include a character read using the {@link #peek()} method. If no * character has been read then this will return {@link Constants#UNDEFINED}. If the end of the stream was reached * on the last read then this will return {@link IOUtils#EOF}. * @@ -116,7 +116,7 @@ final class ExtendedBufferedReader extends BufferedReader { * @throws IOException * If an I/O error occurs */ - int lookAhead() throws IOException { + int peek() throws IOException { super.mark(1); final int c = super.read(); super.reset(); @@ -133,7 +133,7 @@ final class ExtendedBufferedReader extends BufferedReader { * @return the buffer itself * @throws IOException If an I/O error occurs */ - char[] lookAhead(final char[] buf) throws IOException { + char[] peek(final char[] buf) throws IOException { final int n = buf.length; super.mark(n); super.read(buf, 0, n); @@ -192,14 +192,14 @@ final class ExtendedBufferedReader extends BufferedReader { */ @Override public String readLine() throws IOException { - if (lookAhead() == EOF) { + if (peek() == EOF) { return null; } final StringBuilder buffer = new StringBuilder(); while (true) { final int current = read(); if (current == CR) { - final int next = lookAhead(); + final int next = peek(); if (next == LF) { read(); } diff --git a/src/main/java/org/apache/commons/csv/Lexer.java b/src/main/java/org/apache/commons/csv/Lexer.java index f33bd77a..e67c602a 100644 --- a/src/main/java/org/apache/commons/csv/Lexer.java +++ b/src/main/java/org/apache/commons/csv/Lexer.java @@ -105,7 +105,7 @@ final class Lexer implements Closeable { } /** - * Determine whether the next characters constitute a delimiter through {@link ExtendedBufferedReader#lookAhead(char[])}. + * Determine whether the next characters constitute a delimiter through {@link ExtendedBufferedReader#peek(char[])}. * * @param ch * the current character. @@ -121,7 +121,7 @@ final class Lexer implements Closeable { isLastTokenDelimiter = true; return true; } - reader.lookAhead(delimiterBuf); + reader.peek(delimiterBuf); for (int i = 0; i < delimiterBuf.length; i++) { if (delimiterBuf[i] != delimiter[i + 1]) { return false; @@ -151,7 +151,7 @@ final class Lexer implements Closeable { } /** - * Tests if the next characters constitute a escape delimiter through {@link ExtendedBufferedReader#lookAhead(char[])}. + * Tests if the next characters constitute a escape delimiter through {@link ExtendedBufferedReader#peek(char[])}. * * For example, for delimiter "[|]" and escape '!', return true if the next characters constitute "![!|!]". * @@ -159,7 +159,7 @@ final class Lexer implements Closeable { * @throws IOException If an I/O error occurs. */ boolean isEscapeDelimiter() throws IOException { - reader.lookAhead(escapeDelimiterBuf); + reader.peek(escapeDelimiterBuf); if (escapeDelimiterBuf[0] != delimiter[0]) { return false; } @@ -311,7 +311,7 @@ final class Lexer implements Closeable { c = reader.read(); if (isQuoteChar(c)) { - if (isQuoteChar(reader.lookAhead())) { + if (isQuoteChar(reader.peek())) { // double or escaped encapsulator -> add single encapsulator to token c = reader.read(); token.content.append((char) c); @@ -435,7 +435,7 @@ final class Lexer implements Closeable { */ boolean readEndOfLine(int ch) throws IOException { // check if we have \r\n... - if (ch == Constants.CR && reader.lookAhead() == Constants.LF) { + if (ch == Constants.CR && reader.peek() == Constants.LF) { // note: does not change ch outside of this method! ch = reader.read(); // Save the EOL state diff --git a/src/test/java/org/apache/commons/csv/ExtendedBufferedReaderTest.java b/src/test/java/org/apache/commons/csv/ExtendedBufferedReaderTest.java index 07bbae19..b0aec6f8 100644 --- a/src/test/java/org/apache/commons/csv/ExtendedBufferedReaderTest.java +++ b/src/test/java/org/apache/commons/csv/ExtendedBufferedReaderTest.java @@ -40,7 +40,7 @@ public class ExtendedBufferedReaderTest { public void testEmptyInput() throws Exception { try (final ExtendedBufferedReader br = createBufferedReader("")) { assertEquals(EOF, br.read()); - assertEquals(EOF, br.lookAhead()); + assertEquals(EOF, br.peek()); assertEquals(EOF, br.getLastChar()); assertNull(br.readLine()); assertEquals(0, br.read(new char[10], 0, 0)); @@ -116,22 +116,22 @@ public class ExtendedBufferedReaderTest { } try (final ExtendedBufferedReader br = createBufferedReader("foo\n\nhello")) { assertEquals('f', br.read()); - assertEquals('o', br.lookAhead()); + assertEquals('o', br.peek()); assertEquals("oo", br.readLine()); assertEquals(1, br.getCurrentLineNumber()); - assertEquals('\n', br.lookAhead()); + assertEquals('\n', br.peek()); assertEquals("", br.readLine()); assertEquals(2, br.getCurrentLineNumber()); - assertEquals('h', br.lookAhead()); + assertEquals('h', br.peek()); assertEquals("hello", br.readLine()); assertNull(br.readLine()); assertEquals(3, br.getCurrentLineNumber()); } try (final ExtendedBufferedReader br = createBufferedReader("foo\rbaar\r\nfoo")) { assertEquals("foo", br.readLine()); - assertEquals('b', br.lookAhead()); + assertEquals('b', br.peek()); assertEquals("baar", br.readLine()); - assertEquals('f', br.lookAhead()); + assertEquals('f', br.peek()); assertEquals("foo", br.readLine()); assertNull(br.readLine()); } @@ -141,14 +141,14 @@ public class ExtendedBufferedReaderTest { public void testReadLookahead1() throws Exception { try (final ExtendedBufferedReader br = createBufferedReader("1\n2\r3\n")) { assertEquals(0, br.getCurrentLineNumber()); - assertEquals('1', br.lookAhead()); + assertEquals('1', br.peek()); assertEquals(UNDEFINED, br.getLastChar()); assertEquals(0, br.getCurrentLineNumber()); assertEquals('1', br.read()); // Start line 1 assertEquals('1', br.getLastChar()); assertEquals(1, br.getCurrentLineNumber()); - assertEquals('\n', br.lookAhead()); + assertEquals('\n', br.peek()); assertEquals(1, br.getCurrentLineNumber()); assertEquals('1', br.getLastChar()); assertEquals('\n', br.read()); @@ -156,7 +156,7 @@ public class ExtendedBufferedReaderTest { assertEquals('\n', br.getLastChar()); assertEquals(1, br.getCurrentLineNumber()); - assertEquals('2', br.lookAhead()); + assertEquals('2', br.peek()); assertEquals(1, br.getCurrentLineNumber()); assertEquals('\n', br.getLastChar()); assertEquals(1, br.getCurrentLineNumber()); @@ -164,20 +164,20 @@ public class ExtendedBufferedReaderTest { assertEquals(2, br.getCurrentLineNumber()); assertEquals('2', br.getLastChar()); - assertEquals('\r', br.lookAhead()); + assertEquals('\r', br.peek()); assertEquals(2, br.getCurrentLineNumber()); assertEquals('2', br.getLastChar()); assertEquals('\r', br.read()); assertEquals('\r', br.getLastChar()); assertEquals(2, br.getCurrentLineNumber()); - assertEquals('3', br.lookAhead()); + assertEquals('3', br.peek()); assertEquals('\r', br.getLastChar()); assertEquals('3', br.read()); // Start line 3 assertEquals('3', br.getLastChar()); assertEquals(3, br.getCurrentLineNumber()); - assertEquals('\n', br.lookAhead()); + assertEquals('\n', br.peek()); assertEquals(3, br.getCurrentLineNumber()); assertEquals('3', br.getLastChar()); assertEquals('\n', br.read()); @@ -185,12 +185,12 @@ public class ExtendedBufferedReaderTest { assertEquals('\n', br.getLastChar()); assertEquals(3, br.getCurrentLineNumber()); - assertEquals(EOF, br.lookAhead()); + assertEquals(EOF, br.peek()); assertEquals('\n', br.getLastChar()); assertEquals(EOF, br.read()); assertEquals(EOF, br.getLastChar()); assertEquals(EOF, br.read()); - assertEquals(EOF, br.lookAhead()); + assertEquals(EOF, br.peek()); assertEquals(3, br.getCurrentLineNumber()); } @@ -209,7 +209,7 @@ public class ExtendedBufferedReaderTest { assertArrayEquals(ref, res); assertEquals('c', br.getLastChar()); - assertEquals('d', br.lookAhead()); + assertEquals('d', br.peek()); ref[4] = 'd'; assertEquals(1, br.read(res, 4, 1)); assertArrayEquals(ref, res);