/**
   * Serializes this object to an existing {@link HttpRequestBase} which can be sent as an HTTP
   * request. Specifically, sends the object's link, user-defined metadata and vclock as HTTP
   * headers and the value as the body. Used by {@link RiakClient} to create PUT requests.
   *
   * <p>if the this RiakObject's value is a stream, and no length is set, the stream is first
   * buffered into a byte array before being written
   */
  public void writeToHttpMethod(HttpRequestBase httpMethod) {
    // Serialize headers
    String basePath = getBasePathFromHttpMethod(httpMethod);
    writeLinks(httpMethod, basePath);
    for (String name : userMetaData.keySet()) {
      httpMethod.addHeader(Constants.HDR_USERMETA_REQ_PREFIX + name, userMetaData.get(name));
    }

    writeIndexes(httpMethod);

    if (vclock != null) {
      httpMethod.addHeader(Constants.HDR_VCLOCK, vclock);
    }

    // Serialize body
    if (httpMethod instanceof HttpEntityEnclosingRequestBase) {
      HttpEntityEnclosingRequestBase entityEnclosingMethod =
          (HttpEntityEnclosingRequestBase) httpMethod;
      AbstractHttpEntity entity = null;
      // Any value set using setValueAsStream() has precedent over value
      // set using setValue()
      if (valueStream != null) {
        if (valueStreamLength != null && valueStreamLength >= 0) {
          entity = new InputStreamEntity(valueStream, valueStreamLength);
        } else {
          // since apache http client 4.1 no longer supports buffering stream entities, but we can't
          // change API
          // behaviour, here we have to buffer the whole content
          entity = new ByteArrayEntity(ClientUtils.bufferStream(valueStream));
        }
      } else if (value != null) {
        entity = new ByteArrayEntity(value);
      } else {
        entity = new ByteArrayEntity(EMPTY);
      }
      entity.setContentType(contentType);
      entityEnclosingMethod.setEntity(entity);
    }
  }
 /* (non-Javadoc)
  * @see com.basho.riak.client.HttpRiakObject#getLastmodAsDate()
  */
 public Date getLastmodAsDate() {
   return ClientUtils.parseDate(lastmod);
 }