private Entry uploadLastChunk(
      byte[] bytes,
      int position,
      int length,
      String fileType,
      HttpRequestFactory requestFactory,
      long size,
      String location) {

    try {

      HttpResponse response =
          putRequest(bytes, position, length, fileType, requestFactory, size, location);
      if (!response.isSuccessStatusCode()) {
        String message =
            "upload finished, but there was an error during upload, "
                + response.getStatusCode()
                + ": "
                + response.getStatusMessage();
        logger.error(message);
        throw new CoreException(message);
      }

      return response.parseAs(Entry.class);
    } catch (IOException e) {
      String message = "unable to parse response " + e.getMessage();
      logger.error(message);
      throw new CoreException(message);
    }
  }
  private String initUpload(
      HttpRequestFactory requestFactory,
      DocsUrl url,
      long size,
      String fileType,
      AtomContent fileContent)
      throws IOException {
    HttpRequest request = requestFactory.buildPostRequest(url, fileContent);
    request.getHeaders().set("X-Upload-Content-Type", fileType);
    request.getHeaders().set("X-Upload-Content-Length", size);
    HttpResponse response = requestExecutor.executeNonSensitive(request);

    if (!response.isSuccessStatusCode()) {
      throw new CoreException(
          "unable to initiate upload, "
              + response.getStatusCode()
              + ": "
              + response.getStatusMessage());
    }
    response.ignore();
    return response.getHeaders().getLocation();
  }