11 import java.io.CharConversionException;
12 import java.io.IOException;
13 import java.io.Reader;
14 import java.nio.BufferUnderflowException;
15 import java.nio.ByteBuffer;
62 throw new IllegalStateException(
"Reader not closed or reset");
74 public boolean ready() throws IOException {
78 throw new IOException(
"Reader closed");
87 public void close() throws IOException {
102 public int read() throws IOException {
106 return (b >= 0) ? b :
read2(b);
111 throw new IOException(
"Reader closed");
116 private int read2(
byte b)
throws IOException {
122 }
else if (((b & 0xc0) == 0x80) && (
_moreBytes != 0)) {
130 }
else if (((b & 0xe0) == 0xc0) && (
_moreBytes == 0)) {
135 }
else if (((b & 0xf0) == 0xe0) && (
_moreBytes == 0)) {
140 }
else if (((b & 0xf8) == 0xf0) && (
_moreBytes == 0)) {
145 }
else if (((b & 0xfc) == 0xf8) && (
_moreBytes == 0)) {
150 }
else if (((b & 0xfe) == 0xfc) && (
_moreBytes == 0)) {
156 throw new CharConversionException(
"Invalid UTF-8 Encoding");
158 }
catch (BufferUnderflowException e) {
159 throw new CharConversionException(
"Incomplete Sequence");
181 public int read(
char cbuf[],
int off,
int len)
throws IOException {
183 throw new IOException(
"Reader closed");
184 final int off_plus_len = off + len;
188 for (
int i = off; i < off_plus_len;) {
189 if (remaining-- > 0) {
192 cbuf[i++] = (char) b;
194 if (i < off_plus_len - 1) {
197 if (code < 0x10000) {
198 cbuf[i++] = (char) code;
199 }
else if (code <= 0x10ffff) {
200 cbuf[i++] = (char) (((code - 0x10000) >> 10) + 0xd800);
201 cbuf[i++] = (char) (((code - 0x10000) & 0x3ff) + 0xdc00);
203 throw new CharConversionException(
205 + Integer.toHexString(code)
206 +
" to char (code greater than U+10FFFF)");
231 public void read(Appendable dest)
throws IOException {
233 throw new IOException(
"Reader closed");
237 dest.append((
char) b);
240 if (code < 0x10000) {
241 dest.append((
char) code);
242 }
else if (code <= 0x10ffff) {
243 dest.append((
char) (((code - 0x10000) >> 10) + 0xd800));
244 dest.append((
char) (((code - 0x10000) & 0x3ff) + 0xdc00));
246 throw new CharConversionException(
"Cannot convert U+"
247 + Integer.toHexString(code)
248 +
" to char (code greater than U+10FFFF)");