@@ -78,7 +78,7 @@ final class ExtendedBufferedReader extends UnsynchronizedBufferedReader {
7878 * @param charset the character set for encoding, or {@code null} if not applicable.
7979 * @param enableByteTracking {@code true} to enable byte tracking; {@code false} to disable it.
8080 */
81- ExtendedBufferedReader (final Reader reader , Charset charset , boolean enableByteTracking ) {
81+ ExtendedBufferedReader (final Reader reader , final Charset charset , final boolean enableByteTracking ) {
8282 super (reader );
8383 if (charset != null && enableByteTracking ) {
8484 encoder = charset .newEncoder ();
@@ -133,22 +133,21 @@ long getBytesRead() {
133133 * @return the byte length of the character.
134134 * @throws CharacterCodingException if the character cannot be encoded.
135135 */
136- private int getEncodedCharLength (int current ) throws CharacterCodingException {
136+ private int getEncodedCharLength (final int current ) throws CharacterCodingException {
137137 final char cChar = (char ) current ;
138138 final char lChar = (char ) lastChar ;
139139 if (!Character .isSurrogate (cChar )) {
140140 return encoder .encode (
141141 CharBuffer .wrap (new char [] {cChar })).limit ();
142+ }
143+ if (Character .isHighSurrogate (cChar )) {
144+ // Move on to the next char (low surrogate)
145+ return 0 ;
146+ } else if (Character .isSurrogatePair (lChar , cChar )) {
147+ return encoder .encode (
148+ CharBuffer .wrap (new char [] {lChar , cChar })).limit ();
142149 } else {
143- if (Character .isHighSurrogate (cChar )) {
144- // Move on to the next char (low surrogate)
145- return 0 ;
146- } else if (Character .isSurrogatePair (lChar , cChar )) {
147- return encoder .encode (
148- CharBuffer .wrap (new char [] {lChar , cChar })).limit ();
149- } else {
150- throw new CharacterCodingException ();
151- }
150+ throw new CharacterCodingException ();
152151 }
153152 }
154153
0 commit comments