|
43 | 43 | */ |
44 | 44 | final class ExtendedBufferedReader extends UnsynchronizedBufferedReader { |
45 | 45 |
|
| 46 | + /** |
| 47 | + * Measures the byte-order mark that {@code encoder} prepends to every {@link CharsetEncoder#encode(CharBuffer)} call. Charsets such as {@code UTF-16} emit |
| 48 | + * a BOM each time, which would otherwise be counted once per character. The BOM is the constant prefix shared by encoding one and two characters. |
| 49 | + * |
| 50 | + * @param encoder The encoder to measure. |
| 51 | + * @return The byte-order mark length in bytes, or 0 when the encoder writes none. |
| 52 | + */ |
| 53 | + private static int measureBomLength(final CharsetEncoder encoder) { |
| 54 | + try { |
| 55 | + final int one = encoder.encode(CharBuffer.wrap(new char[] { 'a' })).limit(); |
| 56 | + final int two = encoder.encode(CharBuffer.wrap(new char[] { 'a', 'a' })).limit(); |
| 57 | + return Math.max(0, 2 * one - two); |
| 58 | + } catch (final CharacterCodingException e) { |
| 59 | + return 0; |
| 60 | + } |
| 61 | + } |
| 62 | + |
46 | 63 | /** The last char returned */ |
47 | 64 | private int lastChar = UNDEFINED; |
48 | 65 |
|
@@ -166,23 +183,6 @@ private int getEncodedCharLength(final int previous, final int current) throws C |
166 | 183 | throw new CharacterCodingException(); |
167 | 184 | } |
168 | 185 |
|
169 | | - /** |
170 | | - * Measures the byte-order mark that {@code encoder} prepends to every {@link CharsetEncoder#encode(CharBuffer)} call. Charsets such as {@code UTF-16} emit |
171 | | - * a BOM each time, which would otherwise be counted once per character. The BOM is the constant prefix shared by encoding one and two characters. |
172 | | - * |
173 | | - * @param encoder The encoder to measure. |
174 | | - * @return The byte-order mark length in bytes, or 0 when the encoder writes none. |
175 | | - */ |
176 | | - private static int measureBomLength(final CharsetEncoder encoder) { |
177 | | - try { |
178 | | - final int one = encoder.encode(CharBuffer.wrap(new char[] { 'a' })).limit(); |
179 | | - final int two = encoder.encode(CharBuffer.wrap(new char[] { 'a', 'a' })).limit(); |
180 | | - return Math.max(0, 2 * one - two); |
181 | | - } catch (final CharacterCodingException e) { |
182 | | - return 0; |
183 | | - } |
184 | | - } |
185 | | - |
186 | 186 | /** |
187 | 187 | * 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 |
188 | 188 | * 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 |
|
0 commit comments