### Question:
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; }### Answer:
@Test(expected = MalformedInputException.class) public void testUtf8DecodeErrorHandlingFailMalformed() throws IOException { ResettableInputStream in = initUtf8DecodeTest(DecodeErrorPolicy.FAIL); while (in.readChar() != -1) { } fail("Expected MalformedInputException!"); }
@Test public void testUtf8DecodeErrorHandlingIgnore() throws IOException { ResettableInputStream in = initUtf8DecodeTest(DecodeErrorPolicy.IGNORE); int c; StringBuilder sb = new StringBuilder(); while ((c = in.readChar()) != -1) { sb.append((char)c); } assertEquals("Latin1: ()\nLong: ()\nNonUnicode: ()\n", sb.toString()); }
@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()); }
@Test(expected = MalformedInputException.class) public void testLatin1DecodeErrorHandlingFailMalformed() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); generateLatin1InvalidSequence(out); Files.write(out.toByteArray(), file); ResettableInputStream in = initInputStream(DecodeErrorPolicy.FAIL); while (in.readChar() != -1) { } fail("Expected MalformedInputException!"); }
@Test public void testLatin1DecodeErrorHandlingReplace() throws IOException { ByteArrayOutputStream out = new ByteArrayOutputStream(); generateLatin1InvalidSequence(out); Files.write(out.toByteArray(), file); ResettableInputStream in = initInputStream(DecodeErrorPolicy.REPLACE); int c; StringBuilder sb = new StringBuilder(); while ((c = in.readChar()) != -1) { sb.append((char)c); } assertEquals("Invalid: (X)\n".replaceAll("X", "\ufffd"), sb.toString()); }