@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()); } }
@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 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 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); }
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(); }
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();  }