Exemplo n.º 1
0
 public ByteBuffer put(ByteBuffer src) {
   int length = src.remaining();
   checkPut(position, length, false);
   src.get(array, arrayOffset + position, length);
   position += length;
   return this;
 }
Exemplo n.º 2
0
  /**
   * 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;
  }
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 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;
  }