示例#1
0
  /** {@inheritDoc} */
  public void insert(int offset, byte[] values, int valOffset, int len) {
    if (offset == _pos) {
      add(values, valOffset, len);
      return;
    }

    ensureCapacity(_pos + len);
    // shift right
    System.arraycopy(_data, offset, _data, offset + len, _pos - offset);
    // insert
    System.arraycopy(values, valOffset, _data, offset, len);
    _pos += len;
  }
示例#2
0
 /**
  * Grow the internal array as needed to accommodate the specified number of elements. The size of
  * the array bytes on each resize unless capacity requires more than twice the current capacity.
  */
 public void ensureCapacity(int capacity) {
   if (capacity > _data.length) {
     int newCap = Math.max(_data.length << 1, capacity);
     byte[] tmp = new byte[newCap];
     System.arraycopy(_data, 0, tmp, 0, _data.length);
     _data = tmp;
   }
 }
示例#3
0
 /** {@inheritDoc} */
 public byte[] toArray(byte[] dest, int source_pos, int dest_pos, int len) {
   if (len == 0) {
     return dest; // nothing to copy
   }
   if (source_pos < 0 || source_pos >= _pos) {
     throw new ArrayIndexOutOfBoundsException(source_pos);
   }
   System.arraycopy(_data, source_pos, dest, dest_pos, len);
   return dest;
 }
示例#4
0
 /** {@inheritDoc} */
 public byte[] toArray(byte[] dest, int offset, int len) {
   if (len == 0) {
     return dest; // nothing to copy
   }
   if (offset < 0 || offset >= _pos) {
     throw new ArrayIndexOutOfBoundsException(offset);
   }
   System.arraycopy(_data, offset, dest, 0, len);
   return dest;
 }
示例#5
0
  /** {@inheritDoc} */
  public void remove(int offset, int length) {
    if (length == 0) return;
    if (offset < 0 || offset >= _pos) {
      throw new ArrayIndexOutOfBoundsException(offset);
    }

    if (offset == 0) {
      // data at the front
      System.arraycopy(_data, length, _data, 0, _pos - length);
    } else if (_pos - length == offset) {
      // no copy to make, decrementing pos "deletes" values at
      // the end
    } else {
      // data in the middle
      System.arraycopy(_data, offset + length, _data, offset, _pos - (offset + length));
    }
    _pos -= length;
    // no need to clear old values beyond _pos, because this is a
    // primitive collection and 0 takes as much room as any other
    // value
  }
示例#6
0
 /** {@inheritDoc} */
 public void insert(int offset, byte value) {
   if (offset == _pos) {
     add(value);
     return;
   }
   ensureCapacity(_pos + 1);
   // shift right
   System.arraycopy(_data, offset, _data, offset + 1, _pos - offset);
   // insert
   _data[offset] = value;
   _pos++;
 }
示例#7
0
 /** {@inheritDoc} */
 public void set(int offset, byte[] values, int valOffset, int length) {
   if (offset < 0 || offset + length > _pos) {
     throw new ArrayIndexOutOfBoundsException(offset);
   }
   System.arraycopy(values, valOffset, _data, offset, length);
 }
示例#8
0
 /** {@inheritDoc} */
 public void add(byte[] vals, int offset, int length) {
   ensureCapacity(_pos + length);
   System.arraycopy(vals, offset, _data, _pos, length);
   _pos += length;
 }