### Question:
Tailer { public void run() throws IOException { this.line = new byte[4096]; this.pos = 0; byte[] buf = new byte[4096]; while (!Thread.currentThread().isInterrupted()) { int read = src.read(buf); if (read <= 0) { if (isDone()) { flush(pos); return; } try { Thread.sleep(delay); } catch (InterruptedException e) { Thread.currentThread().interrupt(); } } else { while (pos + read >= line.length) { byte[] ab = new byte[line.length * 2]; System.arraycopy(line, 0, ab, 0, line.length); line = ab; } System.arraycopy(buf, 0, line, pos, read); pos += read; int x = -1; for (int i = read - 1; i >= 0; i--) { if (buf[i] == DELIMETER) { x = i; break; } } if (x >= 0) { flush(pos - (read - x) + 1); } } } } Tailer(InputStream src);  Tailer(InputStream src, long delay); void run(); static final long DEFAULT_DELAY; }### Answer:
@Test public void test() throws Exception { List<String> lines = new ArrayList<>(); ByteArrayInputStream in = new ByteArrayInputStream("1\n2\n3".getBytes()); Tailer tailer = new Tailer(in) { @Override protected boolean isDone() { return true; } @Override protected void handle(byte[] buf, int len) { lines.add(new String(buf, 0, len)); } }; tailer.run(); assertEquals(2, lines.size()); assertEquals("1\n2\n", lines.get(0)); assertEquals("3", lines.get(1)); }