@Test public void testInvalidAppendCharArrayAsAscii() throws Exception { final ByteArrayBuffer buffer = new ByteArrayBuffer(4); buffer.append((char[])null, 0, 0); final char[] tmp = new char[] { '1', '2', '3', '4'}; try { buffer.append(tmp, -1, 0); Assert.fail("IndexOutOfBoundsException should have been thrown"); } catch (final IndexOutOfBoundsException ex) { } try { buffer.append(tmp, 0, -1); Assert.fail("IndexOutOfBoundsException should have been thrown"); } catch (final IndexOutOfBoundsException ex) { } try { buffer.append(tmp, 0, 8); Assert.fail("IndexOutOfBoundsException should have been thrown"); } catch (final IndexOutOfBoundsException ex) { } try { buffer.append(tmp, 10, Integer.MAX_VALUE); Assert.fail("IndexOutOfBoundsException should have been thrown"); } catch (final IndexOutOfBoundsException ex) { } try { buffer.append(tmp, 2, 4); Assert.fail("IndexOutOfBoundsException should have been thrown"); } catch (final IndexOutOfBoundsException ex) { } }
public void append(final byte[] b, final int off, final int len) { if (b == null) { return; } if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) < 0) || ((off + len) > b.length)) { throw new IndexOutOfBoundsException("off: "+off+" len: "+len+" b.length: "+b.length); } if (len == 0) { return; } final int newlen = this.len + len; if (newlen > this.array.length) { expand(newlen); } System.arraycopy(b, off, this.array, this.len, len); this.len = newlen; }
ByteArrayBuffer implements Serializable { public void append(final byte[] b, final int off, final int len) { if (b == null) { return; } if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) < 0) || ((off + len) > b.length)) { throw new IndexOutOfBoundsException("off: "+off+" len: "+len+" b.length: "+b.length); } if (len == 0) { return; } final int newlen = this.len + len; if (newlen > this.array.length) { expand(newlen); } System.arraycopy(b, off, this.array, this.len, len); this.len = newlen; } }
ByteArrayBuffer implements Serializable { public void append(final byte[] b, final int off, final int len) { if (b == null) { return; } if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) < 0) || ((off + len) > b.length)) { throw new IndexOutOfBoundsException("off: "+off+" len: "+len+" b.length: "+b.length); } if (len == 0) { return; } final int newlen = this.len + len; if (newlen > this.array.length) { expand(newlen); } System.arraycopy(b, off, this.array, this.len, len); this.len = newlen; } ByteArrayBuffer(final int capacity); }
ByteArrayBuffer implements Serializable { public void append(final byte[] b, final int off, final int len) { if (b == null) { return; } if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) < 0) || ((off + len) > b.length)) { throw new IndexOutOfBoundsException("off: "+off+" len: "+len+" b.length: "+b.length); } if (len == 0) { return; } final int newlen = this.len + len; if (newlen > this.array.length) { expand(newlen); } System.arraycopy(b, off, this.array, this.len, len); this.len = newlen; } ByteArrayBuffer(final int capacity); void append(final byte[] b, final int off, final int len); void append(final int b); void append(final char[] b, final int off, final int len); void append(final CharArrayBuffer b, final int off, final int len); void append(final ByteBuffer buffer); void clear(); byte[] toByteArray(); int byteAt(final int i); int capacity(); int length(); void ensureCapacity(final int required); byte[] array(); void setLength(final int len); boolean isEmpty(); boolean isFull(); int indexOf(final byte b, final int from, final int to); int indexOf(final byte b); }
ByteArrayBuffer implements Serializable { public void append(final byte[] b, final int off, final int len) { if (b == null) { return; } if ((off < 0) || (off > b.length) || (len < 0) || ((off + len) < 0) || ((off + len) > b.length)) { throw new IndexOutOfBoundsException("off: "+off+" len: "+len+" b.length: "+b.length); } if (len == 0) { return; } final int newlen = this.len + len; if (newlen > this.array.length) { expand(newlen); } System.arraycopy(b, off, this.array, this.len, len); this.len = newlen; } ByteArrayBuffer(final int capacity); void append(final byte[] b, final int off, final int len); void append(final int b); void append(final char[] b, final int off, final int len); void append(final CharArrayBuffer b, final int off, final int len); void append(final ByteBuffer buffer); void clear(); byte[] toByteArray(); int byteAt(final int i); int capacity(); int length(); void ensureCapacity(final int required); byte[] array(); void setLength(final int len); boolean isEmpty(); boolean isFull(); int indexOf(final byte b, final int from, final int to); int indexOf(final byte b);  }