示例#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) {
     ensureCapacity(bb.remaining());
     buffer.put(bb);
   }
   return this;
 }
示例#2
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) {
   for (Buffer b : buffers) {
     int pos = (null == buffer ? 0 : buffer.position());
     int len = b.remaining();
     ensureCapacity(len);
     buffer.put(b.byteBuffer());
     buffer.position(pos + len);
   }
   return this;
 }
示例#3
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();
  }
示例#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 <= MAX_BUFFER_SIZE) {
       this.buffer = ByteBuffer.allocate(atLeast);
     } else {
       throw new IllegalArgumentException(
           "Requested buffer size exceeds maximum allowed (" + MAX_BUFFER_SIZE + ")");
     }
   } else {
     ensureCapacity(atLeast);
   }
   this.dynamic = !fixed;
 }
示例#5
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;
 }
示例#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(1);
   buffer.put(b);
   return this;
 }
示例#7
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;
 }
示例#8
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;
 }
示例#9
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;
 }
示例#10
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.putInt(s);
   return this;
 }
示例#11
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;
 }