@Test public void testInsertAt() throws Exception { Buffer buffer = new Buffer(); buffer.write(new byte[]{1,2,3,4}); buffer.insertAt(2, new byte[] {5,6}); Assert.assertArrayEquals(new byte[] {1,2,5,6,3,4}, buffer.toByteArray()); }
public void insertAt(int pos, byte[] data) { ensureCapacity(count + data.length); arraycopy(buf, pos, buf, pos + data.length, count - pos); arraycopy(data, 0, buf, pos, data.length); count += data.length; }
Buffer extends ByteArrayOutputStream { public void insertAt(int pos, byte[] data) { ensureCapacity(count + data.length); arraycopy(buf, pos, buf, pos + data.length, count - pos); arraycopy(data, 0, buf, pos, data.length); count += data.length; } }
Buffer extends ByteArrayOutputStream { public void insertAt(int pos, byte[] data) { ensureCapacity(count + data.length); arraycopy(buf, pos, buf, pos + data.length, count - pos); arraycopy(data, 0, buf, pos, data.length); count += data.length; }  }
Buffer extends ByteArrayOutputStream { public void insertAt(int pos, byte[] data) { ensureCapacity(count + data.length); arraycopy(buf, pos, buf, pos + data.length, count - pos); arraycopy(data, 0, buf, pos, data.length); count += data.length; }  byte[] leadingBytes(int maxSize); byte[] trailingBytes(int maxSize); void insertAt(int pos, byte[] data); int getCapacity(); void ensureCapacity(int minCapacity); }
Buffer extends ByteArrayOutputStream { public void insertAt(int pos, byte[] data) { ensureCapacity(count + data.length); arraycopy(buf, pos, buf, pos + data.length, count - pos); arraycopy(data, 0, buf, pos, data.length); count += data.length; }  byte[] leadingBytes(int maxSize); byte[] trailingBytes(int maxSize); void insertAt(int pos, byte[] data); int getCapacity(); void ensureCapacity(int minCapacity);  }