UnsyncBufferedReader extends Reader { public String readLine() throws IOException { if (_reader == null) { throw new IOException("Reader is null"); } StringBundler sb = null; while (true) { if (_index >= _firstInvalidIndex) { _fillInBuffer(); } if (_index >= _firstInvalidIndex) { if (sb == null) { return null; } return sb.toString(); } boolean hasLineBreak = false; char lineEndChar = 0; int x = _index; int y = _index; while (y < _firstInvalidIndex) { lineEndChar = _buffer[y]; if ((lineEndChar == CharPool.NEW_LINE) || (lineEndChar == CharPool.RETURN)) { hasLineBreak = true; break; } y++; } String line = new String(_buffer, x, y - x); _index = y; if (hasLineBreak) { _index++; if ((lineEndChar == CharPool.RETURN) && (_index < _buffer.length) && (_buffer[_index] == CharPool.NEW_LINE)) { _index++; } if (sb == null) { return line; } sb.append(line); return sb.toString(); } if (sb == null) { sb = new StringBundler(); } sb.append(line); } } UnsyncBufferedReader(Reader reader);  UnsyncBufferedReader(Reader reader, int size); @Override void close(); @Override void mark(int markLimit); @Override boolean markSupported(); @Override int read(); @Override int read(char[] chars); @Override int read(char[] chars, int offset, int length); String readLine(); @Override boolean ready(); @Override void reset(); @Override long skip(long skip);  }
@Test public void testReadLine() throws Exception { UnsyncBufferedReader unsyncBufferedReader = new UnsyncBufferedReader( new StringReader("abc\rde"), 5); Assert.assertEquals("abc", unsyncBufferedReader.readLine()); Assert.assertEquals(4, _indexField.getInt(unsyncBufferedReader)); unsyncBufferedReader = new UnsyncBufferedReader( new StringReader("abc\nde"), 5); Assert.assertEquals("abc", unsyncBufferedReader.readLine()); Assert.assertEquals(4, _indexField.getInt(unsyncBufferedReader)); unsyncBufferedReader = new UnsyncBufferedReader( new StringReader("abc\r\nde"), 5); Assert.assertEquals("abc", unsyncBufferedReader.readLine()); Assert.assertEquals(5, _indexField.getInt(unsyncBufferedReader)); unsyncBufferedReader = new UnsyncBufferedReader( new StringReader("abc"), 5); Assert.assertEquals("abc", unsyncBufferedReader.readLine()); Assert.assertEquals(0, _indexField.getInt(unsyncBufferedReader)); Assert.assertNull(unsyncBufferedReader.readLine()); unsyncBufferedReader = new UnsyncBufferedReader( new StringReader("abcdefghijklmn\r"), 5); Assert.assertEquals("abcdefghijklmn", unsyncBufferedReader.readLine()); Assert.assertEquals(5, _indexField.getInt(unsyncBufferedReader)); unsyncBufferedReader = new UnsyncBufferedReader( new StringReader("abcdefghijklmn\r"), 5); Assert.assertEquals('a', unsyncBufferedReader.read()); Assert.assertEquals('b', unsyncBufferedReader.read()); unsyncBufferedReader.mark(1); }