IntViewBufferImpl(ByteBuffer bb, int capacity) {
   super(capacity, capacity, 0, -1);
   this.bb = bb;
   this.offset = bb.position();
   this.readOnly = bb.isReadOnly();
   this.endian = bb.order();
   if (bb.isDirect()) this.address = VMDirectByteBuffer.adjustAddress(bb.address, offset);
 }
  public IntBuffer compact() {

    int pos = position();
    int lim = limit();
    assert (pos <= lim);
    int rem = (pos <= lim ? lim - pos : 0);

    ByteBuffer db = bb.duplicate();
    db.limit(ix(lim));
    db.position(ix(0));
    ByteBuffer sb = db.slice();
    sb.position(pos << 2);
    sb.compact();
    position(rem);
    limit(capacity());
    return this;
  }
Exemplo n.º 3
0
  /**
   * Compares two <code>ByteBuffer</code> objects.
   *
   * @exception ClassCastException If obj is not an object derived from <code>ByteBuffer</code>.
   */
  public int compareTo(ByteBuffer other) {
    int num = Math.min(remaining(), other.remaining());
    int pos_this = position();
    int pos_other = other.position();

    for (int count = 0; count < num; count++) {
      byte a = get(pos_this++);
      byte b = other.get(pos_other++);

      if (a == b) continue;

      if (a < b) return -1;

      return 1;
    }

    return remaining() - other.remaining();
  }
Exemplo n.º 4
0
 public ByteBuffer asReadOnlyBuffer() {
   ByteBuffer b = new ArrayByteBuffer(array, arrayOffset, capacity, true);
   b.position(position());
   b.limit(limit());
   return b;
 }