@Test public void testUtf8DecodeErrorHandlingReplace() throws IOException { ResettableInputStream in = initUtf8DecodeTest(DecodeErrorPolicy.REPLACE); int c; StringBuilder sb = new StringBuilder(); while ((c = in.readChar()) != -1) { sb.append((char)c); } assertEquals("Latin1: (X)\nLong: (XXX)\nNonUnicode: (X)\n" .replaceAll("X", "\ufffd"), sb.toString()); }
@Override public synchronized int readChar() throws IOException { if (buf.remaining() < maxCharWidth) { buf.clear(); buf.flip(); refillBuf(); } int start = buf.position(); charBuf.clear(); boolean isEndOfInput = false; if (position >= fileSize) { isEndOfInput = true; } CoderResult res = decoder.decode(buf, charBuf, isEndOfInput); if (res.isMalformed() || res.isUnmappable()) { res.throwException(); } int delta = buf.position() - start; charBuf.flip(); if (charBuf.hasRemaining()) { char c = charBuf.get(); incrPosition(delta, !Character.isHighSurrogate(c)); return c; } else { incrPosition(delta, false); return -1; } }
ResettableFileInputStream extends ResettableInputStream implements RemoteMarkable, LengthMeasurable { @Override public synchronized int readChar() throws IOException { if (buf.remaining() < maxCharWidth) { buf.clear(); buf.flip(); refillBuf(); } int start = buf.position(); charBuf.clear(); boolean isEndOfInput = false; if (position >= fileSize) { isEndOfInput = true; } CoderResult res = decoder.decode(buf, charBuf, isEndOfInput); if (res.isMalformed() || res.isUnmappable()) { res.throwException(); } int delta = buf.position() - start; charBuf.flip(); if (charBuf.hasRemaining()) { char c = charBuf.get(); incrPosition(delta, !Character.isHighSurrogate(c)); return c; } else { incrPosition(delta, false); return -1; } } }
ResettableFileInputStream extends ResettableInputStream implements RemoteMarkable, LengthMeasurable { @Override public synchronized int readChar() throws IOException { if (buf.remaining() < maxCharWidth) { buf.clear(); buf.flip(); refillBuf(); } int start = buf.position(); charBuf.clear(); boolean isEndOfInput = false; if (position >= fileSize) { isEndOfInput = true; } CoderResult res = decoder.decode(buf, charBuf, isEndOfInput); if (res.isMalformed() || res.isUnmappable()) { res.throwException(); } int delta = buf.position() - start; charBuf.flip(); if (charBuf.hasRemaining()) { char c = charBuf.get(); incrPosition(delta, !Character.isHighSurrogate(c)); return c; } else { incrPosition(delta, false); return -1; } } ResettableFileInputStream(File file, PositionTracker tracker);  ResettableFileInputStream(File file, PositionTracker tracker,
      int bufSize, Charset charset, DecodeErrorPolicy decodeErrorPolicy); }
ResettableFileInputStream extends ResettableInputStream implements RemoteMarkable, LengthMeasurable { @Override public synchronized int readChar() throws IOException { if (buf.remaining() < maxCharWidth) { buf.clear(); buf.flip(); refillBuf(); } int start = buf.position(); charBuf.clear(); boolean isEndOfInput = false; if (position >= fileSize) { isEndOfInput = true; } CoderResult res = decoder.decode(buf, charBuf, isEndOfInput); if (res.isMalformed() || res.isUnmappable()) { res.throwException(); } int delta = buf.position() - start; charBuf.flip(); if (charBuf.hasRemaining()) { char c = charBuf.get(); incrPosition(delta, !Character.isHighSurrogate(c)); return c; } else { incrPosition(delta, false); return -1; } } ResettableFileInputStream(File file, PositionTracker tracker);  ResettableFileInputStream(File file, PositionTracker tracker,
      int bufSize, Charset charset, DecodeErrorPolicy decodeErrorPolicy); @Override synchronized int read(); @Override synchronized int read(byte[] b, int off, int len); @Override synchronized int readChar(); @Override void mark(); @Override void markPosition(long position); @Override long getMarkPosition(); @Override void reset(); @Override long length(); @Override long tell(); @Override synchronized void seek(long newPos); @Override void close(); }
ResettableFileInputStream extends ResettableInputStream implements RemoteMarkable, LengthMeasurable { @Override public synchronized int readChar() throws IOException { if (buf.remaining() < maxCharWidth) { buf.clear(); buf.flip(); refillBuf(); } int start = buf.position(); charBuf.clear(); boolean isEndOfInput = false; if (position >= fileSize) { isEndOfInput = true; } CoderResult res = decoder.decode(buf, charBuf, isEndOfInput); if (res.isMalformed() || res.isUnmappable()) { res.throwException(); } int delta = buf.position() - start; charBuf.flip(); if (charBuf.hasRemaining()) { char c = charBuf.get(); incrPosition(delta, !Character.isHighSurrogate(c)); return c; } else { incrPosition(delta, false); return -1; } } ResettableFileInputStream(File file, PositionTracker tracker);  ResettableFileInputStream(File file, PositionTracker tracker,
      int bufSize, Charset charset, DecodeErrorPolicy decodeErrorPolicy); @Override synchronized int read(); @Override synchronized int read(byte[] b, int off, int len); @Override synchronized int readChar(); @Override void mark(); @Override void markPosition(long position); @Override long getMarkPosition(); @Override void reset(); @Override long length(); @Override long tell(); @Override synchronized void seek(long newPos); @Override void close(); static final int DEFAULT_BUF_SIZE; }