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);