ByteArray { public synchronized void append(byte[] buffer, int bytesRead) { checkArgument(this.pointer + bytesRead <= this.byteArray.length, "buffer overrun"); System.arraycopy(buffer, 0, this.byteArray, this.pointer, bytesRead); this.pointer += bytesRead; } ByteArray();  ByteArray(int maxLength); boolean contains(byte[] delimiter); synchronized byte[] next(byte[] delimiter); synchronized void append(byte[] buffer, int bytesRead);  }
@Test public void canAppend() { byte[] delimiter = ";".getBytes(); append("abc;def;gh"); assertNextIs(delimiter, "abc"); assertNextIs(delimiter, "def"); append("i;jkl;"); assertNextIs(delimiter, "ghi"); assertNextIs(delimiter, "jkl"); }