ByteBufferAsLongBufferB(ByteBuffer bb) { // package-private super(-1, 0, bb.remaining() >> 3, bb.remaining() >> 3); this.bb = bb; // enforce limit == capacity int cap = this.capacity(); this.limit(cap); int pos = this.position(); assert (pos <= cap); offset = pos; }
/** * Writes the content of the the <code>ByteBUFFER</code> src into the buffer. Before the transfer, * it checks if there is fewer than <code>src.remaining()</code> space remaining in this buffer. * * @param src The source data. * @exception BufferOverflowException If there is insufficient space in this buffer for the * remaining <code>byte</code>s in the source buffer. * @exception IllegalArgumentException If the source buffer is this buffer. * @exception ReadOnlyBufferException If this buffer is read-only. */ public ByteBuffer put(ByteBuffer src) { if (src == this) throw new IllegalArgumentException(); checkForOverflow(src.remaining()); if (src.remaining() > 0) { byte[] toPut = new byte[src.remaining()]; src.get(toPut); put(toPut); } return this; }
public ByteBuffer put(ByteBuffer src) { int length = src.remaining(); checkPut(position, length, false); src.get(array, arrayOffset + position, length); position += length; return this; }
/** * 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(); }
public ByteBuffer put(ByteBuffer src) { if (src instanceof HeapByteBuffer) { if (src == this) throw new IllegalArgumentException(); HeapByteBuffer sb = (HeapByteBuffer) src; int n = sb.remaining(); if (n > remaining()) throw new BufferOverflowException(); System.arraycopy(sb.hb, sb.ix(sb.position()), hb, ix(position()), n); sb.position(sb.position() + n); position(position() + n); } else if (src.isDirect()) { int n = src.remaining(); if (n > remaining()) throw new BufferOverflowException(); src.get(hb, ix(position()), n); position(position() + n); } else { super.put(src); } return this; }