Skip to content

Commit 8cbb558

Browse files
committed
Better internal API
1 parent 14d31b0 commit 8cbb558

2 files changed

Lines changed: 8 additions & 9 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2292,7 +2292,8 @@ 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.peek(lookAheadBuffer));
2295+
bufferedReader.peek(lookAheadBuffer);
2296+
final String test = builder.toString() + new String(lookAheadBuffer);
22962297
final boolean isDelimiterStart = isDelimiter((char) c, test, pos, delimArray, delimLength);
22972298
final boolean isCr = c == Constants.CR;
22982299
final boolean isLf = c == Constants.LF;

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

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -124,21 +124,19 @@ int peek() throws IOException {
124124
}
125125

126126
/**
127-
* Populates the buffer with the next {@code buf.length} characters in the
128-
* current reader without consuming them. The next call to {@link #read()} will
129-
* still return the next value. This doesn't affect the line number or the last
130-
* character.
127+
* Populates the buffer with the next {@code buf.length} characters in the current reader without consuming them. The next call to {@link #read()} will
128+
* still return the next value. This doesn't affect the line number or the last character.
131129
*
132130
* @param buf the buffer to fill for the look ahead.
133-
* @return the buffer itself
131+
* @return The number of characters peeked, or -1 if the end of the stream has been reached.
134132
* @throws IOException If an I/O error occurs
135133
*/
136-
char[] peek(final char[] buf) throws IOException {
134+
int peek(final char[] buf) throws IOException {
137135
final int n = buf.length;
138136
super.mark(n);
139-
super.read(buf, 0, n);
137+
final int c = super.read(buf, 0, n);
140138
super.reset();
141-
return buf;
139+
return c;
142140
}
143141

144142
@Override

0 commit comments

Comments
 (0)