public ByteBuffer allocateBufferIfNeeded() {
    ByteBuffer buffer = getCurrentBuffer();
    if (buffer != null && buffer.hasRemaining()) {
      return buffer;
    }
    if (currentBufferIndex < bufferList.size() - 1) {
      buffer = getBuffer(currentBufferIndex + 1);
    } else {
      buffer = ByteBuffer.allocate(bufferSize);
      bufferList.add(buffer);
    }
    Preconditions.checkArgument(bufferList.size() <= capacity);
    currentBufferIndex++;
    // TODO: Turn the below precondition check on when Standalone pipeline
    // is removed in the write path in tests
    // Preconditions.checkArgument(buffer.position() == 0);
    return buffer;
  }
public ByteBuffer allocateBufferIfNeeded() {
    ByteBuffer buffer = getCurrentBuffer();
    if (buffer != null && buffer.hasRemaining()) {
      return buffer;
    }
    if (currentBufferIndex < bufferList.size() - 1) {
      buffer = getBuffer(currentBufferIndex + 1);
    } else {
      buffer = ByteBuffer.allocate(bufferSize);
      bufferList.add(buffer);
    }
    Preconditions.checkArgument(bufferList.size() <= capacity);
    currentBufferIndex++;
   
   
   
    return buffer;
  }
public bytebuffer allocatebufferifneeded() { bytebuffer buffer = getcurrentbuffer(); if (buffer != null && buffer.hasremaining()) { return buffer; } if (currentbufferindex < bufferlist.size() - 1) { buffer = getbuffer(currentbufferindex + 1); } else { buffer = bytebuffer.allocate(buffersize); bufferlist.add(buffer); } preconditions.checkargument(bufferlist.size() <= capacity); currentbufferindex++; return buffer; }