Skip to content

Commit

Permalink
Make private instance variable final
Browse files Browse the repository at this point in the history
- Use longer lines
  • Loading branch information
garydgregory committed Jan 3, 2025
1 parent 8a827b2 commit 03d2375
Showing 1 changed file with 5 additions and 9 deletions.
14 changes: 5 additions & 9 deletions src/main/java/org/apache/commons/csv/ExtendedBufferedReader.java
Original file line number Diff line number Diff line change
Expand Up @@ -60,13 +60,13 @@ final class ExtendedBufferedReader extends UnsynchronizedBufferedReader {
private long bytesReadMark;

/** Encoder for calculating the number of bytes for each character read. */
private CharsetEncoder encoder;
private final CharsetEncoder encoder;

/**
* Constructs a new instance using the default buffer size.
*/
ExtendedBufferedReader(final Reader reader) {
super(reader);
this(reader, null, false);
}

/**
Expand All @@ -80,9 +80,7 @@ final class ExtendedBufferedReader extends UnsynchronizedBufferedReader {
*/
ExtendedBufferedReader(final Reader reader, final Charset charset, final boolean trackBytes) {
super(reader);
if (charset != null && trackBytes) {
encoder = charset.newEncoder();
}
encoder = charset != null && trackBytes ? charset.newEncoder() : null;
}

/**
Expand Down Expand Up @@ -137,15 +135,13 @@ private int getEncodedCharLength(final int current) throws CharacterCodingExcept
final char cChar = (char) current;
final char lChar = (char) lastChar;
if (!Character.isSurrogate(cChar)) {
return encoder.encode(
CharBuffer.wrap(new char[] {cChar})).limit();
return encoder.encode(CharBuffer.wrap(new char[] { cChar })).limit();
}
if (Character.isHighSurrogate(cChar)) {
// Move on to the next char (low surrogate)
return 0;
} else if (Character.isSurrogatePair(lChar, cChar)) {
return encoder.encode(
CharBuffer.wrap(new char[] {lChar, cChar})).limit();
return encoder.encode(CharBuffer.wrap(new char[] { lChar, cChar })).limit();
} else {
throw new CharacterCodingException();
}
Expand Down

0 comments on commit 03d2375

Please sign in to comment.