Skip to content

Commit

Permalink
Sort members
Browse files Browse the repository at this point in the history
  • Loading branch information
garydgregory committed Sep 19, 2024
1 parent 6a11b89 commit 4f4b9cf
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 52 deletions.
56 changes: 28 additions & 28 deletions src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -56,22 +56,6 @@ final class ExtendedBufferedReader extends UnsynchronizedBufferedReader {
super(reader);
}

@Override
public void mark(final int readAheadLimit) throws IOException {
lineNumberMark = lineNumber;
lastCharMark = lastChar;
positionMark = position;
super.mark(readAheadLimit);
}

@Override
public void reset() throws IOException {
lineNumber = lineNumberMark;
lastChar = lastCharMark;
position = positionMark;
super.reset();
}

/**
* Closes the stream.
*
Expand All @@ -85,6 +69,18 @@ public void close() throws IOException {
super.close();
}

/**
* 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 #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}.
*
* @return the last character that was read
*/
int getLastChar() {
return lastChar;
}

/**
* Returns the current line number
*
Expand All @@ -98,18 +94,6 @@ long getLineNumber() {
return lineNumber + 1; // Allow for counter being incremented only at EOL
}

/**
* 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 #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}.
*
* @return the last character that was read
*/
int getLastChar() {
return lastChar;
}

/**
* Gets the character position in the reader.
*
Expand All @@ -119,6 +103,14 @@ long getPosition() {
return this.position;
}

@Override
public void mark(final int readAheadLimit) throws IOException {
lineNumberMark = lineNumber;
lastCharMark = lastChar;
positionMark = position;
super.mark(readAheadLimit);
}

@Override
public int read() throws IOException {
final int current = super.read();
Expand Down Expand Up @@ -190,4 +182,12 @@ public String readLine() throws IOException {
return buffer.toString();
}

@Override
public void reset() throws IOException {
lineNumber = lineNumberMark;
lastChar = lastCharMark;
position = positionMark;
super.reset();
}

}
48 changes: 24 additions & 24 deletions src/main/java/org/apache/commons/csv/Lexer.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,26 @@ final class Lexer implements Closeable {
this.escapeDelimiterBuf = new char[2 * delimiter.length - 1];
}

/**
* Appends the next escaped character to the token's content.
*
* @param token the current token
* @throws IOException on stream access error
* @throws CSVException Thrown on invalid input.
*/
private void appendNextEscapedCharacterToToken(final Token token) throws IOException {
if (isEscapeDelimiter()) {
token.content.append(delimiter);
} else {
final int unescaped = readEscape();
if (unescaped == EOF) { // unexpected char after escape
token.content.append((char) escape).append((char) reader.getLastChar());
} else {
token.content.append((char) unescaped);
}
}
}

/**
* Closes resources.
*
Expand Down Expand Up @@ -190,10 +210,6 @@ boolean isStartOfLine(final int ch) {
return ch == Constants.LF || ch == Constants.CR || ch == Constants.UNDEFINED;
}

private int nullToDisabled(final Character c) {
return c == null ? Constants.UNDEFINED : c.charValue(); // Explicit unboxing
}

/**
* Returns the next token.
* <p>
Expand Down Expand Up @@ -279,6 +295,10 @@ Token nextToken(final Token token) throws IOException {
return token;
}

private int nullToDisabled(final Character c) {
return c == null ? Constants.UNDEFINED : c.charValue(); // Explicit unboxing
}

/**
* Parses an encapsulated token.
* <p>
Expand Down Expand Up @@ -408,26 +428,6 @@ private Token parseSimpleToken(final Token token, int ch) throws IOException {
return token;
}

/**
* Appends the next escaped character to the token's content.
*
* @param token the current token
* @throws IOException on stream access error
* @throws CSVException Thrown on invalid input.
*/
private void appendNextEscapedCharacterToToken(final Token token) throws IOException {
if (isEscapeDelimiter()) {
token.content.append(delimiter);
} else {
final int unescaped = readEscape();
if (unescaped == EOF) { // unexpected char after escape
token.content.append((char) escape).append((char) reader.getLastChar());
} else {
token.content.append((char) unescaped);
}
}
}

/**
* Greedily accepts \n, \r and \r\n This checker consumes silently the second control-character...
*
Expand Down

0 comments on commit 4f4b9cf

Please sign in to comment.