Example #1
0
 /**
  * Append the given {@link ByteBuffer} to this {@literal Buffer}.
  *
  * @param buffers The {@link ByteBuffer ByteBuffers} to append.
  * @return {@literal this}
  */
 public Buffer append(ByteBuffer... buffers) {
   for (ByteBuffer bb : buffers) {
     if (bb != null) {
       ensureCapacity(bb.remaining());
       buffer.put(bb);
     }
   }
   return this;
 }
Example #2
0
  private void shift(int right) {
    ByteBuffer currentBuffer;
    if (null == buffer) {
      ensureCapacity(right);
      currentBuffer = buffer;
    } else {
      currentBuffer = buffer.slice();
    }

    int len = buffer.remaining();
    int pos = buffer.position();
    ensureCapacity(right + len);

    buffer.position(pos + right);
    buffer.put(currentBuffer);
    buffer.position(pos);

    snapshot();
  }
Example #3
0
 /**
  * Append the given {@link Buffer} to this {@literal Buffer}.
  *
  * @param buffers The {@link Buffer Buffers} to append.
  * @return {@literal this}
  */
 public Buffer append(Buffer... buffers) {
   if (buffers == null) return this;
   for (Buffer b : buffers) {
     if (b == null) continue;
     int pos = position();
     int len = b.remaining();
     ensureCapacity(len);
     if (b.byteBuffer() != null) {
       buffer.put(b.byteBuffer());
       buffer.position(pos + len);
     }
   }
   return this;
 }
Example #4
0
 /**
  * Create an {@literal Buffer} that has an internal {@link ByteBuffer} allocated to the given size
  * and optional make this buffer fixed-length.
  *
  * @param atLeast Allocate this many bytes immediately.
  * @param fixed {@literal true} to make this buffer fixed-length, {@literal false} otherwise.
  */
 public Buffer(int atLeast, boolean fixed) {
   if (fixed) {
     if (atLeast <= ReactiveState.MAX_IO_BUFFER_SIZE) {
       this.buffer = ByteBuffer.allocate(atLeast);
     } else {
       throw new IllegalArgumentException(
           "Requested buffer size exceeds maximum allowed ("
               + ReactiveState.MAX_IO_BUFFER_SIZE
               + ")");
     }
   } else {
     ensureCapacity(atLeast);
   }
   this.dynamic = !fixed;
 }
Example #5
0
 /**
  * Append the given {@code byte[]} to this {@literal Buffer}, starting at the given index and
  * continuing for the given length.
  *
  * @param b the bytes to append
  * @param start the index of where to start copying bytes
  * @param len the len of the bytes to copy
  * @return {@literal this}
  */
 public Buffer append(byte[] b, int start, int len) {
   ensureCapacity(b.length);
   buffer.put(b, start, len);
   return this;
 }
Example #6
0
 /**
  * Append the given {@code byte[]} to this {@literal Buffer}.
  *
  * @param b The {@code byte[]} to append.
  * @return {@literal this}
  */
 public Buffer append(byte[] b) {
   ensureCapacity(b.length);
   buffer.put(b);
   return this;
 }
Example #7
0
 /**
  * Append the given {@code byte} to this {@literal Buffer}.
  *
  * @param b The {@code byte} to append.
  * @return {@literal this}
  */
 public Buffer append(byte b) {
   ensureCapacity(1);
   buffer.put(b);
   return this;
 }
Example #8
0
 /**
  * Append the given {@code char} to this {@literal Buffer}.
  *
  * @param c The {@code char} to append.
  * @return {@literal this}
  */
 public Buffer append(char c) {
   ensureCapacity(2);
   buffer.putChar(c);
   return this;
 }
Example #9
0
 /**
  * Append the given {@code long} to this {@literal Buffer}.
  *
  * @param l The {@code long} to append.
  * @return {@literal this}
  */
 public Buffer append(long l) {
   ensureCapacity(8);
   buffer.putLong(l);
   return this;
 }
Example #10
0
 /**
  * Append the given {@code int} to this {@literal Buffer}.
  *
  * @param i The {@code int} to append.
  * @return {@literal this}
  */
 public Buffer append(int i) {
   ensureCapacity(4);
   buffer.putInt(i);
   return this;
 }
Example #11
0
 /**
  * Append the given {@code short} to this {@literal Buffer}.
  *
  * @param s The {@code short} to append.
  * @return {@literal this}
  */
 public Buffer append(short s) {
   ensureCapacity(2);
   buffer.putShort(s);
   return this;
 }
Example #12
0
 /**
  * Append the given String to this {@literal Buffer}.
  *
  * @param s The String to append.
  * @return {@literal this}
  */
 public Buffer append(String s) {
   ensureCapacity(s.length());
   buffer.put(s.getBytes());
   return this;
 }