@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) { } System.out.println(String.format("[CRAFT-ATOM-UTIL] (^_^) <%s> Case -> test invalid append. ", CaseCounter.incr(5))); }
public ByteArrayBuffer append(final byte[] b, int off, int len) { if (b == null) { return this; } if ((off | len | (b.length - off) | (off + len) | (b.length - off - len)) < 0) { throw new IndexOutOfBoundsException("off: " + off + " len: " + len + " b.length: " + b.length); } if (len == 0) { return this; } int newlen = this.len + len; if (newlen > this.buffer.length) { expand(newlen); } System.arraycopy(b, off, this.buffer, this.len, len); this.len = newlen; return this; }
ByteArrayBuffer implements Serializable { public ByteArrayBuffer append(final byte[] b, int off, int len) { if (b == null) { return this; } if ((off | len | (b.length - off) | (off + len) | (b.length - off - len)) < 0) { throw new IndexOutOfBoundsException("off: " + off + " len: " + len + " b.length: " + b.length); } if (len == 0) { return this; } int newlen = this.len + len; if (newlen > this.buffer.length) { expand(newlen); } System.arraycopy(b, off, this.buffer, this.len, len); this.len = newlen; return this; } }
ByteArrayBuffer implements Serializable { public ByteArrayBuffer append(final byte[] b, int off, int len) { if (b == null) { return this; } if ((off | len | (b.length - off) | (off + len) | (b.length - off - len)) < 0) { throw new IndexOutOfBoundsException("off: " + off + " len: " + len + " b.length: " + b.length); } if (len == 0) { return this; } int newlen = this.len + len; if (newlen > this.buffer.length) { expand(newlen); } System.arraycopy(b, off, this.buffer, this.len, len); this.len = newlen; return this; } ByteArrayBuffer();  ByteArrayBuffer(int capacity);  ByteArrayBuffer(final byte[] bytes); }
ByteArrayBuffer implements Serializable { public ByteArrayBuffer append(final byte[] b, int off, int len) { if (b == null) { return this; } if ((off | len | (b.length - off) | (off + len) | (b.length - off - len)) < 0) { throw new IndexOutOfBoundsException("off: " + off + " len: " + len + " b.length: " + b.length); } if (len == 0) { return this; } int newlen = this.len + len; if (newlen > this.buffer.length) { expand(newlen); } System.arraycopy(b, off, this.buffer, this.len, len); this.len = newlen; return this; } ByteArrayBuffer();  ByteArrayBuffer(int capacity);  ByteArrayBuffer(final byte[] bytes); ByteArrayBuffer append(final byte[] b, int off, int len); ByteArrayBuffer append(byte b); ByteArrayBuffer append(final byte[] b); void clear(); void reset(int capacity); byte[] array(); byte[] array(int start, int end); byte byteAt(int i); int capacity(); int length(); byte[] buffer(); boolean isEmpty(); boolean isFull(); int indexOf(byte b); int indexOf(byte b, int beginIndex, int endIndex); int indexOf(byte[] bytes); int indexOf(byte[] bytes, int beginIndex); int indexOf(byte[] bytes, int beginIndex, int endIndex); }
ByteArrayBuffer implements Serializable { public ByteArrayBuffer append(final byte[] b, int off, int len) { if (b == null) { return this; } if ((off | len | (b.length - off) | (off + len) | (b.length - off - len)) < 0) { throw new IndexOutOfBoundsException("off: " + off + " len: " + len + " b.length: " + b.length); } if (len == 0) { return this; } int newlen = this.len + len; if (newlen > this.buffer.length) { expand(newlen); } System.arraycopy(b, off, this.buffer, this.len, len); this.len = newlen; return this; } ByteArrayBuffer();  ByteArrayBuffer(int capacity);  ByteArrayBuffer(final byte[] bytes); ByteArrayBuffer append(final byte[] b, int off, int len); ByteArrayBuffer append(byte b); ByteArrayBuffer append(final byte[] b); void clear(); void reset(int capacity); byte[] array(); byte[] array(int start, int end); byte byteAt(int i); int capacity(); int length(); byte[] buffer(); boolean isEmpty(); boolean isFull(); int indexOf(byte b); int indexOf(byte b, int beginIndex, int endIndex); int indexOf(byte[] bytes); int indexOf(byte[] bytes, int beginIndex); int indexOf(byte[] bytes, int beginIndex, int endIndex);  }