### Question:
InterleavedReader implements Closeable { public Object read() throws IOException { char[] buffer = new char[BUFFER_LENGTH]; reader.mark(BUFFER_LENGTH); int count = 0; int textEnd; while (true) { int r = reader.read(buffer, count, buffer.length - count); if (r == -1) { textEnd = count; break; } count += r; int possibleMarker = findPossibleMarker(buffer, count); if (possibleMarker != 0) { textEnd = possibleMarker; break; } if (count < marker.length()) { continue; } reader.reset(); String json = reader.readLine().substring(marker.length()); return jsonParser.parse(json); } if (count == 0) { return null; } reader.reset(); count = reader.read(buffer, 0, textEnd); return new String(buffer, 0, count); } InterleavedReader(Reader reader);  InterleavedReader(String marker, Reader reader); Object read(); @Override void close(); static final String DEFAULT_MARKER; }### Answer:
@Test public void newlineCharacters() throws IOException { InterleavedReader reader = new InterleavedReader(" + " assertEquals("abc", reader.read()); assertEqualsJson("{\"z\":\"y\\nx\"}", reader.read()); assertEquals(null, reader.read()); }
@Test public void characterByCharacter() throws IOException { InterleavedReader reader = new InterleavedReader(" + " + " + " assertEquals("a", reader.read()); assertEquals("b", reader.read()); assertEquals("c", reader.read()); assertEqualsJson("{\"z\":0}", reader.read()); assertEquals(" assertEquals("e", reader.read()); assertEquals("f", reader.read()); assertEquals(" assertEquals("h", reader.read()); assertEquals("i", reader.read()); assertEquals("/j", reader.read()); assertEquals("/k", reader.read()); assertEqualsJson("{\"y\":0}", reader.read()); assertEquals(" }
@Test public void inputBufferedReader() throws IOException { InterleavedReader reader = new InterleavedReader(" new BufferedReader(new StringReader("abc assertEquals("abc", reader.read()); assertEqualsJson("{\"z\":0}", reader.read()); assertEquals(null, reader.read()); }
@Test public void basic() throws IOException { InterleavedReader reader = new InterleavedReader(" + " + " + "def + "ghi\n" + "jkl\n" + " assertEquals("abc\n", reader.read()); assertEqualsJson("{\"z\":0}", reader.read()); assertEqualsJson("{\"y\":0}", reader.read()); assertEquals("def", reader.read()); assertEqualsJson("{\"x\":0}", reader.read()); assertEquals("ghi\njkl\n", reader.read()); assertEqualsJson("{\"w\":0}", reader.read()); assertEquals(null, reader.read()); }
@Test public void endsWithMarkerPrefix() throws IOException { InterleavedReader reader = new InterleavedReader(" assertEquals("abc", reader.read()); assertEquals(" assertEquals(null, reader.read()); }