@Test public void testInvalidAppend() throws Exception { ByteArrayBuffer buffer = new ByteArrayBuffer(4); buffer.append((byte[]) null, 0, 0); byte[] tmp = new byte[]{1, 2, 3, 4}; try { buffer.append(tmp, -1, 0); Assert.fail("IndexOutOfBoundsException should have been thrown"); } catch (IndexOutOfBoundsException ex) { } try { buffer.append(tmp, 0, -1); Assert.fail("IndexOutOfBoundsException should have been thrown"); } catch (IndexOutOfBoundsException ex) { } try { buffer.append(tmp, 0, 8); Assert.fail("IndexOutOfBoundsException should have been thrown"); } catch (IndexOutOfBoundsException ex) { } try { buffer.append(tmp, 10, Integer.MAX_VALUE); Assert.fail("IndexOutOfBoundsException should have been thrown"); } catch (IndexOutOfBoundsException ex) { } try { buffer.append(tmp, 2, 4); Assert.fail("IndexOutOfBoundsException should have been thrown"); } catch (IndexOutOfBoundsException ex) { } }
public void append(final byte[] b, int off, int len) { if (b == null) { return; } if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) < 0) || ((off + len) > b.length)) { throw new IndexOutOfBoundsException(); } if (len == 0) { return; } int newlen = this.len + len; if (newlen > this.buffer.length) { expand(newlen); } System.arraycopy(b, off, this.buffer, this.len, len); this.len = newlen; }
ByteArrayBuffer implements ByteSequence { public void append(final byte[] b, int off, int len) { if (b == null) { return; } if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) < 0) || ((off + len) > b.length)) { throw new IndexOutOfBoundsException(); } if (len == 0) { return; } int newlen = this.len + len; if (newlen > this.buffer.length) { expand(newlen); } System.arraycopy(b, off, this.buffer, this.len, len); this.len = newlen; } }
ByteArrayBuffer implements ByteSequence { public void append(final byte[] b, int off, int len) { if (b == null) { return; } if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) < 0) || ((off + len) > b.length)) { throw new IndexOutOfBoundsException(); } if (len == 0) { return; } int newlen = this.len + len; if (newlen > this.buffer.length) { expand(newlen); } System.arraycopy(b, off, this.buffer, this.len, len); this.len = newlen; } ByteArrayBuffer(int capacity);  ByteArrayBuffer(byte[] bytes, boolean dontCopy);  ByteArrayBuffer(byte[] bytes, int len, boolean dontCopy); }
ByteArrayBuffer implements ByteSequence { public void append(final byte[] b, int off, int len) { if (b == null) { return; } if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) < 0) || ((off + len) > b.length)) { throw new IndexOutOfBoundsException(); } if (len == 0) { return; } int newlen = this.len + len; if (newlen > this.buffer.length) { expand(newlen); } System.arraycopy(b, off, this.buffer, this.len, len); this.len = newlen; } ByteArrayBuffer(int capacity);  ByteArrayBuffer(byte[] bytes, boolean dontCopy);  ByteArrayBuffer(byte[] bytes, int len, boolean dontCopy); void append(final byte[] b, int off, int len); void append(int b); void clear(); byte[] toByteArray(); byte byteAt(int i); int capacity(); int length(); byte[] buffer(); int indexOf(byte b); int indexOf(byte b, int beginIndex, int endIndex); void setLength(int len); void remove(int off, int len); boolean isEmpty(); boolean isFull(); @Override String toString(); }
ByteArrayBuffer implements ByteSequence { public void append(final byte[] b, int off, int len) { if (b == null) { return; } if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) < 0) || ((off + len) > b.length)) { throw new IndexOutOfBoundsException(); } if (len == 0) { return; } int newlen = this.len + len; if (newlen > this.buffer.length) { expand(newlen); } System.arraycopy(b, off, this.buffer, this.len, len); this.len = newlen; } ByteArrayBuffer(int capacity);  ByteArrayBuffer(byte[] bytes, boolean dontCopy);  ByteArrayBuffer(byte[] bytes, int len, boolean dontCopy); void append(final byte[] b, int off, int len); void append(int b); void clear(); byte[] toByteArray(); byte byteAt(int i); int capacity(); int length(); byte[] buffer(); int indexOf(byte b); int indexOf(byte b, int beginIndex, int endIndex); void setLength(int len); void remove(int off, int len); boolean isEmpty(); boolean isFull(); @Override String toString();  }