LookAheadReader extends Reader { public String peekLine() throws IOException { fillNextLine(); return nextLine; } LookAheadReader(Reader reader); String readLine(); String peekLine(); @Override void close(); @Override int read(char[] cbuf, int off, int len);  }
@Test public void peekLine() throws IOException { try (LookAheadReader reader = new LookAheadReader(new StringReader("one\rtwo"))) { assertEquals("one", reader.peekLine()); assertEquals("one", reader.peekLine()); assertEquals("one", reader.readLine()); assertEquals("two", reader.peekLine()); assertEquals("two", reader.readLine()); assertEquals(null, reader.readLine()); assertEquals(null, reader.readLine()); } }