Hi.
I am using your library for one of my projects.
Given the ByteArrayList, the following two methods can be very handy:
public byte[] removeElementsFromTo(int fromIndex,int toIndex,boolean
returnArray) {
if (fromIndex <0 ||this._size < fromIndex) {
throw new IndexOutOfBoundsException("From-index should be at least 0 and less than
" +this._size +", found " + fromIndex);
}
if (toIndex <1 ||this._size <= toIndex) {
throw new IndexOutOfBoundsException("To-index should be at least 1 and less than or
equal to " +this._size +", found " + toIndex);
}
if (toIndex <= fromIndex) {
throw new IndexOutOfBoundsException("From-index must lie before to-index."
+"from-index=" + fromIndex +", to-index=" + toIndex);
}
int length = toIndex - fromIndex;
byte[] removedBytes =null;
this.incrModCount();
if (0 < length) {
if (returnArray) {
removedBytes =new byte[length];
System.arraycopy(this._data, fromIndex, removedBytes,0, length);
}
System.arraycopy(this._data, fromIndex + length,this._data, fromIndex,
length);
this._size -= length;
}else {
if (returnArray) {
removedBytes =new byte[0];
}
}
return removedBytes;
}
public void addElementsAt(int index,byte[] elements) {
this.checkRangeIncludingEndpoint(index);
this.incrModCount();
this.ensureCapacity(this._size + elements.length);
int numtomove =this._size - index - elements.length;
System.arraycopy(this._data, index,this._data, index + elements.length,
numtomove);
System.arraycopy(elements,0,this._data, index, elements.length);
this._size+=elements.length;
}
They avoid copying arrays for every single byte.
Maybe you want to add them.
Best regards,'
Michael MIrwaldt