EolBufferedReader { public String readLineKeepStartEol() throws IOException { StringBuilder stringBuilder = new StringBuilder(); synchronized (monitor) { int read = reader.read(); if (read == -1) { return null; } stringBuilder.append((char) read); if (read == '\r') { read = reader.read(); if (read == -1) { return stringBuilder.toString(); } stringBuilder.append((char) read); } while(true) { reader.mark(1); read = reader.read(); if (read == -1) { break; } if (read == '\n' || read == '\r') { reader.reset(); break; } stringBuilder.append((char) read); } } return stringBuilder.toString(); } EolBufferedReader(BufferedReader bufferedReader); String readLineKeepEol(); String readLineKeepStartEol(); void close();  }
@Test public void readLineKeepStartEOLTest() throws IOException { EolBufferedReader reader = null; try { reader = new EolBufferedReader(new BufferedReader(new StringReader(TEST_STRING))); String line1 = reader.readLineKeepStartEol(); String line2 = reader.readLineKeepStartEol(); String line3 = reader.readLineKeepStartEol(); String line4 = reader.readLineKeepStartEol(); String line5 = reader.readLineKeepStartEol(); String line6 = reader.readLineKeepStartEol(); Assert.assertFalse(startsWithEol(line1)); Assert.assertFalse(endsWithEol(line1)); Assert.assertEquals(removeEol(line1), "line1"); Assert.assertEquals(getStartEol(line1), null); Assert.assertEquals(getEndEol(line1), null); Assert.assertTrue(startsWithEol(line2)); Assert.assertFalse(endsWithEol(line2)); Assert.assertEquals(removeEol(line2), "line2"); Assert.assertEquals(getStartEol(line2), "\n"); Assert.assertEquals(getEndEol(line2), null); Assert.assertTrue(startsWithEol(line3)); Assert.assertFalse(endsWithEol(line3)); Assert.assertEquals(removeEol(line3), "line3"); Assert.assertEquals(getStartEol(line3), "\r"); Assert.assertEquals(getEndEol(line3), null); Assert.assertTrue(startsWithEol(line4)); Assert.assertTrue(endsWithEol(line4)); Assert.assertEquals(removeEol(line4), ""); Assert.assertEquals(getStartEol(line4), "\r\n"); Assert.assertEquals(getEndEol(line4), "\r\n"); Assert.assertTrue(startsWithEol(line5)); Assert.assertTrue(endsWithEol(line5)); Assert.assertEquals(removeEol(line5), ""); Assert.assertEquals(getStartEol(line5), "\n"); Assert.assertEquals(getEndEol(line5), "\n"); Assert.assertNull(line6); } finally { if(reader != null) reader.close(); } }