### Question:
LineInputStream extends FilterInputStream { @SuppressWarnings("deprecation") public String readLine() throws IOException { byte[] buf = lineBuffer; if (buf == null) buf = lineBuffer = new byte[128]; int c1; int room = buf.length; int offset = 0; while ((c1 = in.read()) != -1) { if (c1 == '\n') break; else if (c1 == '\r') { boolean twoCRs = false; if (in.markSupported()) in.mark(2); int c2 = in.read(); if (c2 == '\r') { twoCRs = true; c2 = in.read(); } if (c2 != '\n') { if (in.markSupported()) in.reset(); else { if (!(in instanceof PushbackInputStream)) in = new PushbackInputStream(in, 2); if (c2 != -1) ((PushbackInputStream)in).unread(c2); if (twoCRs) ((PushbackInputStream)in).unread('\r'); } } break; } if (--room < 0) { if (buf.length < MAX_INCR) buf = new byte[buf.length * 2]; else buf = new byte[buf.length + MAX_INCR]; room = buf.length - offset - 1; System.arraycopy(lineBuffer, 0, buf, 0, offset); lineBuffer = buf; } buf[offset++] = (byte)c1; } if ((c1 == -1) && (offset == 0)) return null; if (allowutf8) return new String(buf, 0, offset, StandardCharsets.UTF_8); else { if (defaultutf8) { try { return decoder.decode(ByteBuffer.wrap(buf, 0, offset)). toString(); } catch (CharacterCodingException cex) { } } return new String(buf, 0, 0, offset); } } LineInputStream(InputStream in);  LineInputStream(InputStream in, boolean allowutf8); @SuppressWarnings("deprecation") // for old String constructor String readLine();  }### Answer:
@Test public void testLines() throws IOException { for (String s : lines) { LineInputStream is = createStream(s); assertEquals("line1", is.readLine()); assertEquals("line2", is.readLine()); assertEquals("line3", is.readLine()); assertEquals(null, is.readLine()); } }
@Test public void testEmpty() throws IOException { for (String s : empty) { LineInputStream is = createStream(s); assertEquals("", is.readLine()); assertEquals("", is.readLine()); assertEquals("", is.readLine()); assertEquals(null, is.readLine()); } }
@Test public void testMixed() throws IOException { for (String s : mixed) { LineInputStream is = createStream(s); assertEquals("line1", is.readLine()); assertEquals("", is.readLine()); assertEquals("line3", is.readLine()); assertEquals(null, is.readLine()); } }
@Test public void testUtf8Fail() throws IOException { LineInputStream is = createStream("a\u00A9b\n", StandardCharsets.UTF_8); assertNotEquals("a\u00A9b", is.readLine()); }
@Test public void testUtf8() throws IOException { LineInputStream is = new LineInputStream(new ByteArrayInputStream( "a\u00A9b\n".getBytes(StandardCharsets.UTF_8)), true); assertEquals("a\u00A9b", is.readLine()); }
@Test public void testIso() throws IOException { LineInputStream is = createStream("a\251b\n", StandardCharsets.ISO_8859_1); assertEquals("a\251b", is.readLine()); }