@Test public void testMultiByte() throws Exception { InputStreamReader isr = new InputStreamReader(new ByteArrayInputStream(new byte[] {(byte)80, (byte)-61, (byte)-70}), Charset.forName("UTF-8").newDecoder(), 2); assertEquals(80, isr.read()); assertEquals(250, isr.read()); }
@Override public int read(char[] cbuf, int off, int len) throws IOException { if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } while (!done && !cb.hasRemaining()) { int read = 0; int pos = bb.position(); while ((read = rbc.read(bb)) == 0) { } bb.flip(); cb.clear(); CoderResult cr = cd.decode(bb, cb, read == -1); checkResult(cr); if (read == -1) { cr = cd.flush(cb); checkResult(cr); done = true; } bytesProcessed += bb.position() - pos; if (bb.position() != read + pos) { bb.compact(); } else { bb.clear(); } cb.flip(); } len = Math.min(len, cb.remaining()); if (len == 0 && done) { return -1; } cb.get(cbuf, off, len); return len; }
InputStreamReader extends Reader { @Override public int read(char[] cbuf, int off, int len) throws IOException { if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } while (!done && !cb.hasRemaining()) { int read = 0; int pos = bb.position(); while ((read = rbc.read(bb)) == 0) { } bb.flip(); cb.clear(); CoderResult cr = cd.decode(bb, cb, read == -1); checkResult(cr); if (read == -1) { cr = cd.flush(cb); checkResult(cr); done = true; } bytesProcessed += bb.position() - pos; if (bb.position() != read + pos) { bb.compact(); } else { bb.clear(); } cb.flip(); } len = Math.min(len, cb.remaining()); if (len == 0 && done) { return -1; } cb.get(cbuf, off, len); return len; } }
InputStreamReader extends Reader { @Override public int read(char[] cbuf, int off, int len) throws IOException { if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } while (!done && !cb.hasRemaining()) { int read = 0; int pos = bb.position(); while ((read = rbc.read(bb)) == 0) { } bb.flip(); cb.clear(); CoderResult cr = cd.decode(bb, cb, read == -1); checkResult(cr); if (read == -1) { cr = cd.flush(cb); checkResult(cr); done = true; } bytesProcessed += bb.position() - pos; if (bb.position() != read + pos) { bb.compact(); } else { bb.clear(); } cb.flip(); } len = Math.min(len, cb.remaining()); if (len == 0 && done) { return -1; } cb.get(cbuf, off, len); return len; } InputStreamReader(InputStream in, CharsetDecoder cd);  InputStreamReader(InputStream in, CharsetDecoder cd, int bufferSize); }
InputStreamReader extends Reader { @Override public int read(char[] cbuf, int off, int len) throws IOException { if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } while (!done && !cb.hasRemaining()) { int read = 0; int pos = bb.position(); while ((read = rbc.read(bb)) == 0) { } bb.flip(); cb.clear(); CoderResult cr = cd.decode(bb, cb, read == -1); checkResult(cr); if (read == -1) { cr = cd.flush(cb); checkResult(cr); done = true; } bytesProcessed += bb.position() - pos; if (bb.position() != read + pos) { bb.compact(); } else { bb.clear(); } cb.flip(); } len = Math.min(len, cb.remaining()); if (len == 0 && done) { return -1; } cb.get(cbuf, off, len); return len; } InputStreamReader(InputStream in, CharsetDecoder cd);  InputStreamReader(InputStream in, CharsetDecoder cd, int bufferSize); @Override void close(); @Override int read(char[] cbuf, int off, int len); }
InputStreamReader extends Reader { @Override public int read(char[] cbuf, int off, int len) throws IOException { if ((off < 0) || (off > cbuf.length) || (len < 0) || ((off + len) > cbuf.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } while (!done && !cb.hasRemaining()) { int read = 0; int pos = bb.position(); while ((read = rbc.read(bb)) == 0) { } bb.flip(); cb.clear(); CoderResult cr = cd.decode(bb, cb, read == -1); checkResult(cr); if (read == -1) { cr = cd.flush(cb); checkResult(cr); done = true; } bytesProcessed += bb.position() - pos; if (bb.position() != read + pos) { bb.compact(); } else { bb.clear(); } cb.flip(); } len = Math.min(len, cb.remaining()); if (len == 0 && done) { return -1; } cb.get(cbuf, off, len); return len; } InputStreamReader(InputStream in, CharsetDecoder cd);  InputStreamReader(InputStream in, CharsetDecoder cd, int bufferSize); @Override void close(); @Override int read(char[] cbuf, int off, int len);  }