* @param bytesWritten The number of bytes that have been successfully uploaded on the server
*/
private void setContentAndHeadersOnCurrentRequest(long bytesWritten) throws IOException {
int blockSize = (int) Math.min(chunkSize, getMediaContentLength() - bytesWritten);
// TODO(rmistry): Add tests for LimitInputStream.
InputStreamContent contentChunk =
new InputStreamContent(mediaContent.getType(),
new LimitInputStream(contentInputStream, blockSize));
contentChunk.setCloseInputStream(false);
contentChunk.setRetrySupported(true);
contentChunk.setLength(blockSize);
// Mark the current position in case we need to retry the request.
contentInputStream.mark(blockSize);
currentRequest.setContent(contentChunk);
currentRequest.getHeaders().setContentRange("bytes " + bytesWritten + "-"
+ (bytesWritten + blockSize - 1) + "/" + getMediaContentLength());