Skip to content

Commit 14d31b0

Browse files
committed
Rename internal methods
1 parent ca1ed20 commit 14d31b0

4 files changed

Lines changed: 27 additions & 27 deletions

File tree

src/main/java/org/apache/commons/csv/CSVFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,7 @@ private void printWithEscapes(final Reader reader, final Appendable appendable)
22922292
while (EOF != (c = bufferedReader.read())) {
22932293
builder.append((char) c);
22942294
Arrays.fill(lookAheadBuffer, (char) 0);
2295-
final String test = builder.toString() + new String(bufferedReader.lookAhead(lookAheadBuffer));
2295+
final String test = builder.toString() + new String(bufferedReader.peek(lookAheadBuffer));
22962296
final boolean isDelimiterStart = isDelimiter((char) c, test, pos, delimArray, delimLength);
22972297
final boolean isCr = c == Constants.CR;
22982298
final boolean isLf = c == Constants.LF;

src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ long getCurrentLineNumber() {
8484

8585
/**
8686
* Returns the last character that was read as an integer (0 to 65535). This will be the last character returned by
87-
* any of the read methods. This will not include a character read using the {@link #lookAhead()} method. If no
87+
* any of the read methods. This will not include a character read using the {@link #peek()} method. If no
8888
* character has been read then this will return {@link Constants#UNDEFINED}. If the end of the stream was reached
8989
* on the last read then this will return {@link IOUtils#EOF}.
9090
*
@@ -116,7 +116,7 @@ public boolean isClosed() {
116116
* @throws IOException
117117
* If an I/O error occurs
118118
*/
119-
int lookAhead() throws IOException {
119+
int peek() throws IOException {
120120
super.mark(1);
121121
final int c = super.read();
122122
super.reset();
@@ -133,7 +133,7 @@ int lookAhead() throws IOException {
133133
* @return the buffer itself
134134
* @throws IOException If an I/O error occurs
135135
*/
136-
char[] lookAhead(final char[] buf) throws IOException {
136+
char[] peek(final char[] buf) throws IOException {
137137
final int n = buf.length;
138138
super.mark(n);
139139
super.read(buf, 0, n);
@@ -192,14 +192,14 @@ public int read(final char[] buf, final int offset, final int length) throws IOE
192192
*/
193193
@Override
194194
public String readLine() throws IOException {
195-
if (lookAhead() == EOF) {
195+
if (peek() == EOF) {
196196
return null;
197197
}
198198
final StringBuilder buffer = new StringBuilder();
199199
while (true) {
200200
final int current = read();
201201
if (current == CR) {
202-
final int next = lookAhead();
202+
final int next = peek();
203203
if (next == LF) {
204204
read();
205205
}

src/main/java/org/apache/commons/csv/Lexer.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ boolean isCommentStart(final int ch) {
105105
}
106106

107107
/**
108-
* Determine whether the next characters constitute a delimiter through {@link ExtendedBufferedReader#lookAhead(char[])}.
108+
* Determine whether the next characters constitute a delimiter through {@link ExtendedBufferedReader#peek(char[])}.
109109
*
110110
* @param ch
111111
* the current character.
@@ -121,7 +121,7 @@ boolean isDelimiter(final int ch) throws IOException {
121121
isLastTokenDelimiter = true;
122122
return true;
123123
}
124-
reader.lookAhead(delimiterBuf);
124+
reader.peek(delimiterBuf);
125125
for (int i = 0; i < delimiterBuf.length; i++) {
126126
if (delimiterBuf[i] != delimiter[i + 1]) {
127127
return false;
@@ -151,15 +151,15 @@ boolean isEscape(final int ch) {
151151
}
152152

153153
/**
154-
* Tests if the next characters constitute a escape delimiter through {@link ExtendedBufferedReader#lookAhead(char[])}.
154+
* Tests if the next characters constitute a escape delimiter through {@link ExtendedBufferedReader#peek(char[])}.
155155
*
156156
* For example, for delimiter "[|]" and escape '!', return true if the next characters constitute "![!|!]".
157157
*
158158
* @return true if the next characters constitute an escape delimiter.
159159
* @throws IOException If an I/O error occurs.
160160
*/
161161
boolean isEscapeDelimiter() throws IOException {
162-
reader.lookAhead(escapeDelimiterBuf);
162+
reader.peek(escapeDelimiterBuf);
163163
if (escapeDelimiterBuf[0] != delimiter[0]) {
164164
return false;
165165
}
@@ -311,7 +311,7 @@ private Token parseEncapsulatedToken(final Token token) throws IOException {
311311
c = reader.read();
312312

313313
if (isQuoteChar(c)) {
314-
if (isQuoteChar(reader.lookAhead())) {
314+
if (isQuoteChar(reader.peek())) {
315315
// double or escaped encapsulator -> add single encapsulator to token
316316
c = reader.read();
317317
token.content.append((char) c);
@@ -435,7 +435,7 @@ private void appendNextEscapedCharacterToToken(final Token token) throws IOExcep
435435
*/
436436
boolean readEndOfLine(int ch) throws IOException {
437437
// check if we have \r\n...
438-
if (ch == Constants.CR && reader.lookAhead() == Constants.LF) {
438+
if (ch == Constants.CR && reader.peek() == Constants.LF) {
439439
// note: does not change ch outside of this method!
440440
ch = reader.read();
441441
// Save the EOL state

src/test/java/org/apache/commons/csv/ExtendedBufferedReaderTest.java

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ private ExtendedBufferedReader createBufferedReader(final String s) {
4040
public void testEmptyInput() throws Exception {
4141
try (final ExtendedBufferedReader br = createBufferedReader("")) {
4242
assertEquals(EOF, br.read());
43-
assertEquals(EOF, br.lookAhead());
43+
assertEquals(EOF, br.peek());
4444
assertEquals(EOF, br.getLastChar());
4545
assertNull(br.readLine());
4646
assertEquals(0, br.read(new char[10], 0, 0));
@@ -116,22 +116,22 @@ public void testReadLine() throws Exception {
116116
}
117117
try (final ExtendedBufferedReader br = createBufferedReader("foo\n\nhello")) {
118118
assertEquals('f', br.read());
119-
assertEquals('o', br.lookAhead());
119+
assertEquals('o', br.peek());
120120
assertEquals("oo", br.readLine());
121121
assertEquals(1, br.getCurrentLineNumber());
122-
assertEquals('\n', br.lookAhead());
122+
assertEquals('\n', br.peek());
123123
assertEquals("", br.readLine());
124124
assertEquals(2, br.getCurrentLineNumber());
125-
assertEquals('h', br.lookAhead());
125+
assertEquals('h', br.peek());
126126
assertEquals("hello", br.readLine());
127127
assertNull(br.readLine());
128128
assertEquals(3, br.getCurrentLineNumber());
129129
}
130130
try (final ExtendedBufferedReader br = createBufferedReader("foo\rbaar\r\nfoo")) {
131131
assertEquals("foo", br.readLine());
132-
assertEquals('b', br.lookAhead());
132+
assertEquals('b', br.peek());
133133
assertEquals("baar", br.readLine());
134-
assertEquals('f', br.lookAhead());
134+
assertEquals('f', br.peek());
135135
assertEquals("foo", br.readLine());
136136
assertNull(br.readLine());
137137
}
@@ -141,56 +141,56 @@ public void testReadLine() throws Exception {
141141
public void testReadLookahead1() throws Exception {
142142
try (final ExtendedBufferedReader br = createBufferedReader("1\n2\r3\n")) {
143143
assertEquals(0, br.getCurrentLineNumber());
144-
assertEquals('1', br.lookAhead());
144+
assertEquals('1', br.peek());
145145
assertEquals(UNDEFINED, br.getLastChar());
146146
assertEquals(0, br.getCurrentLineNumber());
147147
assertEquals('1', br.read()); // Start line 1
148148
assertEquals('1', br.getLastChar());
149149

150150
assertEquals(1, br.getCurrentLineNumber());
151-
assertEquals('\n', br.lookAhead());
151+
assertEquals('\n', br.peek());
152152
assertEquals(1, br.getCurrentLineNumber());
153153
assertEquals('1', br.getLastChar());
154154
assertEquals('\n', br.read());
155155
assertEquals(1, br.getCurrentLineNumber());
156156
assertEquals('\n', br.getLastChar());
157157
assertEquals(1, br.getCurrentLineNumber());
158158

159-
assertEquals('2', br.lookAhead());
159+
assertEquals('2', br.peek());
160160
assertEquals(1, br.getCurrentLineNumber());
161161
assertEquals('\n', br.getLastChar());
162162
assertEquals(1, br.getCurrentLineNumber());
163163
assertEquals('2', br.read()); // Start line 2
164164
assertEquals(2, br.getCurrentLineNumber());
165165
assertEquals('2', br.getLastChar());
166166

167-
assertEquals('\r', br.lookAhead());
167+
assertEquals('\r', br.peek());
168168
assertEquals(2, br.getCurrentLineNumber());
169169
assertEquals('2', br.getLastChar());
170170
assertEquals('\r', br.read());
171171
assertEquals('\r', br.getLastChar());
172172
assertEquals(2, br.getCurrentLineNumber());
173173

174-
assertEquals('3', br.lookAhead());
174+
assertEquals('3', br.peek());
175175
assertEquals('\r', br.getLastChar());
176176
assertEquals('3', br.read()); // Start line 3
177177
assertEquals('3', br.getLastChar());
178178
assertEquals(3, br.getCurrentLineNumber());
179179

180-
assertEquals('\n', br.lookAhead());
180+
assertEquals('\n', br.peek());
181181
assertEquals(3, br.getCurrentLineNumber());
182182
assertEquals('3', br.getLastChar());
183183
assertEquals('\n', br.read());
184184
assertEquals(3, br.getCurrentLineNumber());
185185
assertEquals('\n', br.getLastChar());
186186
assertEquals(3, br.getCurrentLineNumber());
187187

188-
assertEquals(EOF, br.lookAhead());
188+
assertEquals(EOF, br.peek());
189189
assertEquals('\n', br.getLastChar());
190190
assertEquals(EOF, br.read());
191191
assertEquals(EOF, br.getLastChar());
192192
assertEquals(EOF, br.read());
193-
assertEquals(EOF, br.lookAhead());
193+
assertEquals(EOF, br.peek());
194194
assertEquals(3, br.getCurrentLineNumber());
195195

196196
}
@@ -209,7 +209,7 @@ public void testReadLookahead2() throws Exception {
209209
assertArrayEquals(ref, res);
210210
assertEquals('c', br.getLastChar());
211211

212-
assertEquals('d', br.lookAhead());
212+
assertEquals('d', br.peek());
213213
ref[4] = 'd';
214214
assertEquals(1, br.read(res, 4, 1));
215215
assertArrayEquals(ref, res);

0 commit comments

Comments
 (0)