/** * Make a <code>ByteArray</code> available for access at the end of this object. * * @param ba The ByteArray to append */ public final void append(ByteArray ba) { cba.addLast(ba); }
/** * Free all resources associated with this object. */ public final void free() { cba.free(); }
private void checkBounds(int index, int accessSize) { int lower = index; int upper = index + accessSize; if (lower < first()) { throw new IndexOutOfBoundsException("Index " + lower + " less than start " + first() + "."); } if (upper > last()) { throw new IndexOutOfBoundsException("Index " + upper + " greater than length " + last() + "."); } } }
if (index < first() || index > last()) { throw new IndexOutOfBoundsException(); CompositeByteArray prefix = new CompositeByteArray(byteArrayFactory); int remaining = index - first(); ByteArray component = removeFirst(); prefix.addLast(component); remaining -= component.last(); } else { prefix.addLast(ba1); remaining -= ba1.last(); addFirst(ba2);
/** * {@inheritDoc} */ @Override public void put(int index, IoBuffer bb) { cursor(index).put(bb); }
/** * {@inheritDoc} */ @Override public ByteArray slice(int length) { CompositeByteArray slice = new CompositeByteArray(byteArrayFactory); int remaining = length; while (remaining > 0) { prepareForAccess(remaining); int componentSliceSize = Math.min(remaining, componentCursor.getRemaining()); ByteArray componentSlice = componentCursor.slice(componentSliceSize); slice.addLast(componentSlice); index += componentSliceSize; remaining -= componentSliceSize; } return slice; }
/** * Adds the specified {@link ByteArray} to the first * position in the list * * @param ba The ByteArray to add to the list */ public void addFirst(ByteArray ba) { addHook(ba); bas.addFirst(ba); }
/** * {@inheritDoc} */ @Override public ByteOrder order() { return CompositeByteArray.this.order(); }
/** * @return the index after the last byte that can be accessed. */ public final int last() { return cba.last(); }
if (index < first() || index > last()) { throw new IndexOutOfBoundsException(); CompositeByteArray prefix = new CompositeByteArray(byteArrayFactory); int remaining = index - first(); ByteArray component = removeFirst(); prefix.addLast(component); remaining -= component.last(); } else { prefix.addLast(ba1); remaining -= ba1.last(); addFirst(ba2);
/** * {@inheritDoc} */ @Override public long getLong(int index) { return cursor(index).getLong(); }
private void checkBounds(int index, int accessSize) { int lower = index; int upper = index + accessSize; if (lower < first()) { throw new IndexOutOfBoundsException("Index " + lower + " less than start " + first() + "."); } if (upper > last()) { throw new IndexOutOfBoundsException("Index " + upper + " greater than length " + last() + "."); } } }
/** * @inheritDoc */ public ByteArray slice( int length ) { CompositeByteArray slice = new CompositeByteArray( byteArrayFactory ); int remaining = length; while ( remaining > 0 ) { prepareForAccess( remaining ); int componentSliceSize = Math.min( remaining, componentCursor.getRemaining() ); ByteArray componentSlice = componentCursor.slice( componentSliceSize ); slice.addLast( componentSlice ); index += componentSliceSize; remaining -= componentSliceSize; } return slice; }
/** * Adds the specified {@link ByteArray} to the end of the list * * @param ba The ByteArray to add to the end of the list */ public void addLast(ByteArray ba) { addHook(ba); bas.addLast(ba); }
/** * @return The used byte order (little of big indian) */ public ByteOrder order() { return cba.order(); }