/**
  * Creates CreateFileRangeResult object from $parsed response in array
  * representation
  *
  * @param array $headers HTTP response headers
  *
  * @return CreateFileRangeResult
  */
 public static function create($headers)
 {
     $result = new CreateFileRangeResult();
     $clean = array_change_key_case($headers);
     $date = $clean[Resources::LAST_MODIFIED];
     $date = Utilities::rfc1123ToDateTime($date);
     $result->setETag($clean[Resources::ETAG]);
     $result->setLastModified($date);
     $result->setContentMD5(Utilities::tryGetValue($clean, Resources::CONTENT_MD5));
     return $result;
 }
 /**
  * Does actual work for create and clear file ranges.
  *
  * @param string                 $action        Either clear or create.
  * @param string                 $share         The share name.
  * @param string                 $directoryPath The directory path.
  * @param string                 $file          The file name.
  * @param FileRange              $range         The file range.
  * @param string|resource        $content       The content stream.
  * @param CreateFileRangeOptions $options       The optional parameters.
  *
  * @return CreateFileRangeResult
  */
 private function _updateFileRangeImpl($action, $share, $directoryPath, $file, $range, $content, $options = null)
 {
     Validate::isString($share, 'share');
     Validate::notNullOrEmpty($share, 'share');
     Validate::isString($directoryPath, 'directoryPath');
     Validate::isString($file, 'file');
     Validate::isTrue($range instanceof FileRange, sprintf(Resources::INVALID_PARAM_MSG, 'range', get_class(new FileRange())));
     Validate::isTrue(is_string($content) || is_resource($content), sprintf(Resources::INVALID_PARAM_MSG, 'content', 'string|resource'));
     $method = Resources::HTTP_PUT;
     $headers = array();
     $queryParams = array();
     $postParams = array();
     $path = $this->_createPath($share, $directoryPath, $file);
     $statusCode = Resources::STATUS_CREATED;
     // If read file failed for any reason it will throw an exception.
     $body = is_resource($content) ? stream_get_contents($content) : $content;
     if (is_null($options)) {
         $options = new CreateFileRangeOptions();
     }
     $headers[Resources::CONTENT_LENGTH] = $action == FileWriteOption::CLEAR_OPTION ? 0 : strlen($body);
     $headers = $this->_addOptionalRangeHeader($headers, $range->getStart(), $range->getEnd());
     $headers = $this->addOptionalAccessConditionHeader($headers, $options->getAccessCondition());
     $this->addOptionalHeader($headers, Resources::CONTENT_MD5, $options->getContentMD5());
     $this->addOptionalHeader($headers, Resources::X_MS_WRITE, $action);
     $this->addOptionalHeader($headers, Resources::CONTENT_TYPE, Resources::URL_ENCODED_CONTENT_TYPE);
     $this->addOptionalQueryParam($queryParams, Resources::QP_COMP, 'range');
     $this->addOptionalQueryParam($queryParams, Resources::QP_TIMEOUT, $options->getTimeout());
     $response = $this->send($method, $headers, $queryParams, $postParams, $path, $statusCode, $body);
     return CreateFileRangeResult::create($response->getHeader());
 }