@Test public void testUTF8() throws Exception { FileInputStream fis = new FileInputStream(UnitTestUtil.getTestDataFile("legal_notice.xml")); ReaderInputStream ris = new ReaderInputStream(new FileReader(UnitTestUtil.getTestDataFile("legal_notice.xml")), Charset.forName("UTF-8")); int value; while (true) { value = fis.read(); assertEquals(value, ris.read()); if (value == -1) { break; } } }
@Override public int read(byte[] bbuf, int off, int len) throws IOException { if ((off < 0) || (off > bbuf.length) || (len < 0) || ((off + len) > bbuf.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } while (!done && !bb.hasRemaining()) { int read = 0; int pos = cb.position(); if (!wasOverflow) { while ((read = reader.read(cb)) == 0) { } cb.flip(); } bb.clear(); CoderResult cr = encoder.encode(cb, bb, read == -1); checkResult(cr); if (read == -1 && !wasOverflow) { cr = encoder.flush(bb); checkResult(cr); if (!wasOverflow) { done = true; } } if (!wasOverflow) { if (read != 0 && cb.position() != read + pos) { cb.compact(); } else { cb.clear(); } } bb.flip(); } len = Math.min(len, bb.remaining()); if (len == 0 && done) { return -1; } bb.get(bbuf, off, len); return len; }
ReaderInputStream extends InputStream { @Override public int read(byte[] bbuf, int off, int len) throws IOException { if ((off < 0) || (off > bbuf.length) || (len < 0) || ((off + len) > bbuf.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } while (!done && !bb.hasRemaining()) { int read = 0; int pos = cb.position(); if (!wasOverflow) { while ((read = reader.read(cb)) == 0) { } cb.flip(); } bb.clear(); CoderResult cr = encoder.encode(cb, bb, read == -1); checkResult(cr); if (read == -1 && !wasOverflow) { cr = encoder.flush(bb); checkResult(cr); if (!wasOverflow) { done = true; } } if (!wasOverflow) { if (read != 0 && cb.position() != read + pos) { cb.compact(); } else { cb.clear(); } } bb.flip(); } len = Math.min(len, bb.remaining()); if (len == 0 && done) { return -1; } bb.get(bbuf, off, len); return len; } }
ReaderInputStream extends InputStream { @Override public int read(byte[] bbuf, int off, int len) throws IOException { if ((off < 0) || (off > bbuf.length) || (len < 0) || ((off + len) > bbuf.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } while (!done && !bb.hasRemaining()) { int read = 0; int pos = cb.position(); if (!wasOverflow) { while ((read = reader.read(cb)) == 0) { } cb.flip(); } bb.clear(); CoderResult cr = encoder.encode(cb, bb, read == -1); checkResult(cr); if (read == -1 && !wasOverflow) { cr = encoder.flush(bb); checkResult(cr); if (!wasOverflow) { done = true; } } if (!wasOverflow) { if (read != 0 && cb.position() != read + pos) { cb.compact(); } else { cb.clear(); } } bb.flip(); } len = Math.min(len, bb.remaining()); if (len == 0 && done) { return -1; } bb.get(bbuf, off, len); return len; } ReaderInputStream(Reader reader, Charset charset);  ReaderInputStream(Reader reader, CharsetEncoder encoder);  ReaderInputStream(Reader reader, CharsetEncoder encoder, int bufferSize); }
ReaderInputStream extends InputStream { @Override public int read(byte[] bbuf, int off, int len) throws IOException { if ((off < 0) || (off > bbuf.length) || (len < 0) || ((off + len) > bbuf.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } while (!done && !bb.hasRemaining()) { int read = 0; int pos = cb.position(); if (!wasOverflow) { while ((read = reader.read(cb)) == 0) { } cb.flip(); } bb.clear(); CoderResult cr = encoder.encode(cb, bb, read == -1); checkResult(cr); if (read == -1 && !wasOverflow) { cr = encoder.flush(bb); checkResult(cr); if (!wasOverflow) { done = true; } } if (!wasOverflow) { if (read != 0 && cb.position() != read + pos) { cb.compact(); } else { cb.clear(); } } bb.flip(); } len = Math.min(len, bb.remaining()); if (len == 0 && done) { return -1; } bb.get(bbuf, off, len); return len; } ReaderInputStream(Reader reader, Charset charset);  ReaderInputStream(Reader reader, CharsetEncoder encoder);  ReaderInputStream(Reader reader, CharsetEncoder encoder, int bufferSize); @Override int read(byte[] bbuf, int off, int len); @Override int read(); @Override void close(); }
ReaderInputStream extends InputStream { @Override public int read(byte[] bbuf, int off, int len) throws IOException { if ((off < 0) || (off > bbuf.length) || (len < 0) || ((off + len) > bbuf.length) || ((off + len) < 0)) { throw new IndexOutOfBoundsException(); } else if (len == 0) { return 0; } while (!done && !bb.hasRemaining()) { int read = 0; int pos = cb.position(); if (!wasOverflow) { while ((read = reader.read(cb)) == 0) { } cb.flip(); } bb.clear(); CoderResult cr = encoder.encode(cb, bb, read == -1); checkResult(cr); if (read == -1 && !wasOverflow) { cr = encoder.flush(bb); checkResult(cr); if (!wasOverflow) { done = true; } } if (!wasOverflow) { if (read != 0 && cb.position() != read + pos) { cb.compact(); } else { cb.clear(); } } bb.flip(); } len = Math.min(len, bb.remaining()); if (len == 0 && done) { return -1; } bb.get(bbuf, off, len); return len; } ReaderInputStream(Reader reader, Charset charset);  ReaderInputStream(Reader reader, CharsetEncoder encoder);  ReaderInputStream(Reader reader, CharsetEncoder encoder, int bufferSize); @Override int read(byte[] bbuf, int off, int len); @Override int read(); @Override void close();  }