### Question:
MultiLineReader implements BlockTextReader { public String read() throws IOException { if (eof) { return null; } synchronized (lock) { String current; while (true) { current = reader.readLine(); if (current == null) { eof = true; return off > 0 ? new String(buf, 0, off) : null; } if (isLinetail(current)) { fill(current); String ret = new String(buf, 0, off); off = 0; return ret; } if (isLinehead(current) && off > 0) { String ret = new String(buf, 0, off); off = 0; fill(current); return ret; } fill(current); } } } MultiLineReader();  MultiLineReader(InputStream in);  MultiLineReader(Reader reader);  MultiLineReader(BufferedReader reader); @Override BlockTextReader wrap(InputStream in); String read(); @Override void close();  }### Answer:
@Test public void testString() throws IOException { String text = "hello\nworld\n"; ByteArrayInputStream bis = new ByteArrayInputStream(text.getBytes()); MultiLineReader reader = new MultiLineReader(bis); String line; while(true) { line = reader.read(); if (line == null) { break; } System.out.println(line); } }
@Test public void testInputStream() throws IOException { MultiLineReader reader = new MultiLineReader(getClass().getClassLoader().getResourceAsStream("buffered_read_long.txt")); int lineCount = 0; String line; while(true) { line = reader.read(); if (line == null) { break; } lineCount++; } Assert.assertEquals(5, lineCount); }