Prepare the buffer for sending.

@param key the key (for keyed ops).
@param cas the cas value.
@param val the data payload.
@param extraHeaders any additional headers that need to be sent.
423808
protected void prepareBuffer(final String key, final long cas,
    final byte[] val, final Object... extraHeaders) {
    int extraLen = 0;
    int extraHeadersLength = extraHeaders.length;

    if (extraHeadersLength > 0) {
      extraLen = calculateExtraLength(extraHeaders);
    }

    final byte[] keyBytes = KeyUtil.getKeyBytes(key);
    int bufSize = MIN_RECV_PACKET + keyBytes.length + val.length;

    ByteBuffer bb = ByteBuffer.allocate(bufSize + extraLen);
    assert bb.order() == ByteOrder.BIG_ENDIAN;
    bb.put(REQ_MAGIC);
    bb.put(cmd);
    bb.putShort((short) keyBytes.length);
    bb.put((byte) extraLen);
    bb.put((byte) 0);
    bb.putShort(vbucket);
    bb.putInt(keyBytes.length + val.length + extraLen);
    bb.putInt(opaque);
    bb.putLong(cas);

    if (extraHeadersLength > 0) {
      addExtraHeaders(bb, extraHeaders);
    }

    bb.put(keyBytes);
    bb.put(val);

    bb.flip();
    setBuffer(bb);
  }
528327
public void addHeader(String key, String value) {
    this.headers = addToMap(key, value, this.headers);
  }
1089751
public static void addString(ByteBuffer buffer, String val)
  {
    addBytes(buffer, StringUtils.toUtf8(val));
  }
963865
protected void addBasicAuthHeader(HttpHeaders headers, String key){
		headers.add(HEADER_AUTHORIZATION, buildBasicAuthValue(key));
	}
664882
public void addPayload(IoBuffer additionalPayload) {
        if (payload == null) {
            payload = IoBuffer.allocate(additionalPayload.remaining());
            payload.setAutoExpand(true);
        }
        this.payload.put(additionalPayload);
    }
338412
private static boolean isApplicationHeader(String key) {
    // Don't allow reserved non HTTP/2 pseudo headers to be added
    // HTTP/2 headers can not be created as keys because Header.Key disallows the ':' character.
    return !CONTENT_TYPE_KEY.name().equalsIgnoreCase(key)
        && !USER_AGENT_KEY.name().equalsIgnoreCase(key)
        && !TE_HEADER.name().equalsIgnoreCase(key);
  }
470249
public static void writeUnsignedVarint(ByteBuffer buffer, int val) {
    // Extra bytes have the high bit set
    while((val & 0x7F) != val) {
      buffer.put((byte) ((val & 0x7F) | 0x80));
      val >>>= 7;
    }
    // Last byte doesn't have high bit set
    buffer.put((byte) (val & 0x7F));
  }
609444
public void init(byte[] IV, byte[] key) {
		if(IV.length != key.length)
			throw new Exceptions.InvalidKeyException("Key and IV size must be equal.");
		keySize = key.length;
		this.key = key;
		prehash = Misc.cleanXOR(IV, key);
		blockNo = 0;
		buffer = new ByteQueue(blockSize*2);
		buffer.setResizable(true);
		cfg = true;
	}
820173
private void writeExternalPKey(ObjectOutput out)
                    throws java.io.IOException {

        // write the serialized primary key - can't mix eternaized stream
        // and writeObject so convert to bytes...
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream pkeyStream = new ObjectOutputStream(baos);
        pkeyStream.writeObject(pkey);
        pkeyStream.flush();
        pkeyStream.close();
        byte[] pkeyBytes = baos.toByteArray();
        out.writeInt(pkeyBytes.length);
        out.write(pkeyBytes);
    }
397226
@Override
    public void expire(K key, V val) {
        if (val == null) {
            return;
        }
        try {
            TupleInfo tupleInfo = (TupleInfo) val;
            FailSpoutMsg fail = new FailSpoutMsg(key, spout, tupleInfo, taskStats);

            disruptorEventQueue.publish(fail);
        } catch (Exception e) {
            LOG.error("expire error", e);
        }
    }
829330
public void setBytes(String key, byte[] bytes) {
		String encoded = new String(Base64.encodeBase64(bytes));
		setStringInternal(key, encoded);
	}
1007548
public void cache(Object key, T val) {
        cache.put(key, new SoftReference<T>(val));
    }
714952
public SearchParameters addExtraParameter(String key, Object o) {
        extraParameters.put(checkNotNull(key), o);
        return this;
    }
791254
static public void put( Key key, Value val, Futures fs ) {
    assert !val.isLockable();
    Value res = DKV.put(key,val,fs);
    assert res == null || !res.isLockable();
  }
198294
public void put(Key key, Value val) {
		if (val == null) st.remove(key);
		else             st.put(key, val);
	}
711505
public void addHeaderOutImpl(String key, String value)
  {
    if (headerOutSpecial(key, value)) {
      return;
    }
    
    ArrayList<String> keys = _headerKeysOut;
    ArrayList<String> values = _headerValuesOut;
    
    int size = keys.size();
    
    // webapp/1k32
    for (int i = 0; i < size; i++) {
      if (keys.get(i).equals(key) && values.get(i).equals(value)) {
        return;
      }
    }

    keys.add(key);
    values.add(value);
  }
236632
@Override
	public void init(Key key, IvParameterSpec iv) throws InvalidKeyException {
		if(!(key instanceof SecretKey))
			throw new InvalidKeyException();
		int ivLength = iv.getIV().length;
		if(key.getEncoded().length < MIN_KEY_SIZE || key.getEncoded().length < ivLength)
			throw new InvalidKeyException("Key must be longer than " + MIN_KEY_SIZE + " bytes and key must be longer than IV.");
		this.key = key.getEncoded();
		this.iv = iv;
		prehash = Misc.XORintoA(this.key.length == ivLength ? iv.getIV() : Arrays.copyOf(iv.getIV(), this.key.length), this.key);
		blockNo = 0;
		buffer = new ByteQueue(getBlockSize()*2);
		buffer.setResizable(true);
		cfg = true;
	}