<commit_before><?php

/**
 * LICENSE: Licensed under the Apache License, Version 2.0 (the "License")
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * PHP version 5
 *
 * @category  Microsoft
 * @package   WindowsAzure\Services\Blob\BlobRestProxy
 * @author    <NAME> <<EMAIL>>
 * @copyright 2012 Microsoft Corporation
 * @license   http://www.apache.org/licenses/LICENSE-2.0  Apache License 2.0
 * @link      http://pear.php.net/package/azure-sdk-for-php
 */
 
namespace WindowsAzure\Services\Blob;
use WindowsAzure\Utilities;
use WindowsAzure\Resources;
use WindowsAzure\Validate;
use WindowsAzure\Core\WindowsAzureUtilities;
use WindowsAzure\Services\Core\Models\ServiceProperties;
use WindowsAzure\Services\Core\ServiceRestProxy;
use WindowsAzure\Services\Blob\IBlob;
use WindowsAzure\Services\Blob\Models\BlobServiceOptions;
use WindowsAzure\Services\Core\Models\GetServicePropertiesResult;
use WindowsAzure\Services\Blob\Models\ListContainersOptions;
use WindowsAzure\Services\Blob\Models\ListContainersResult;
use WindowsAzure\Services\Blob\Models\CreateContainerOptions;
use WindowsAzure\Services\Blob\Models\GetContainerPropertiesResult;
use WindowsAzure\Services\Blob\Models\GetContainerAclResult;
use WindowsAzure\Services\Blob\Models\SetContainerMetadataOptions;
use WindowsAzure\Services\Blob\Models\DeleteContainerOptions;
use WindowsAzure\Services\Blob\Models\ListBlobsOptions;
use WindowsAzure\Services\Blob\Models\ListBlobsResult;
use WindowsAzure\Services\Blob\Models\BlobType;
use WindowsAzure\Services\Blob\Models\CreateBlobOptions;
use WindowsAzure\Services\Blob\Models\BlobProperties;
use WindowsAzure\Services\Blob\Models\GetBlobPropertiesOptions;
use WindowsAzure\Services\Blob\Models\GetBlobPropertiesResult;
use WindowsAzure\Services\Blob\Models\SetBlobPropertiesOptions;
use WindowsAzure\Services\Blob\Models\SetBlobPropertiesResult;
use WindowsAzure\Services\Blob\Models\GetBlobMetadataOptions;
use WindowsAzure\Services\Blob\Models\GetBlobMetadataResult;
use WindowsAzure\Services\Blob\Models\SetBlobMetadataOptions;
use WindowsAzure\Services\Blob\Models\SetBlobMetadataResult;
use WindowsAzure\Services\Blob\Models\GetBlobOptions;
use WindowsAzure\Services\Blob\Models\GetBlobResult;
use WindowsAzure\Services\Blob\Models\DeleteBlobOptions;
use WindowsAzure\Services\Blob\Models\LeaseMode;
use WindowsAzure\Services\Blob\Models\AcquireLeaseOptions;
use WindowsAzure\Services\Blob\Models\AcquireLeaseResult;
use WindowsAzure\Services\Blob\Models\CreateBlobPagesOptions;
use WindowsAzure\Services\Blob\Models\CreateBlobPagesResult;
use WindowsAzure\Services\Blob\Models\PageWriteOption;
use WindowsAzure\Services\Blob\Models\ListPageBlobRangesOptions;
use WindowsAzure\Services\Blob\Models\ListPageBlobRangesResult;
use WindowsAzure\Services\Blob\Models\CreateBlobBlockOptions;
use WindowsAzure\Services\Blob\Models\CommitBlobBlocksOptions;
use WindowsAzure\Services\Blob\Models\BlockList;
use WindowsAzure\Services\Blob\Models\ListBlobBlocksOptions;
use WindowsAzure\Services\Blob\Models\ListBlobBlocksResult;
use WindowsAzure\Services\Blob\Models\CopyBlobOptions;
use WindowsAzure\Services\Blob\Models\CreateBlobSnapshotOptions;
use WindowsAzure\Services\Blob\Models\CreateBlobSnapshotResult;

/**
 * This class constructs HTTP requests and receive HTTP responses for blob
 * service layer.
 *
 * @category  Microsoft
 * @package   WindowsAzure\Services\Blob\BlobRestProxy
 * @author    <NAME> <<EMAIL>>
 * @copyright 2012 Microsoft Corporation
 * @license   http://www.apache.org/licenses/LICENSE-2.0  Apache License 2.0
 * @version   Release: @package_version@
 * @link      http://pear.php.net/package/azure-sdk-for-php
 */
class BlobRestProxy extends ServiceRestProxy implements IBlob
{
    /**
     * Creates URI path for blob.
     * 
     * @param string $container The container name.
     * @param string $blob      The blob name.
     * 
     * @return string
     */
    private function _createPath($container, $blob)
    {
        // Empty container means accessing default container
        if (empty($container)) {
            return $blob;
        } else {
            return $container . '/' . $blob;
        }
    }
    
    /**
     * Creates GetBlobPropertiesResult from headers array.
     * 
     * @param array $headers The HTTP response headers array.
     * 
     * @return GetBlobPropertiesResult
     */
    private function _getBlobPropertiesResultFromResponse($headers)
    {
        $result     = new GetBlobPropertiesResult();
        $properties = new BlobProperties();
        $d          = $headers[Resources::LAST_MODIFIED];
        $bType      = $headers[Resources::X_MS_BLOB_TYPE];
        $lStatus    = $headers[Resources::X_MS_LEASE_STATUS];
        $cLength    = intval($headers[Resources::CONTENT_LENGTH]);
        $cType      = Utilities::tryGetValue($headers, Resources::CONTENT_TYPE);
        $cMD5       = Utilities::tryGetValue($headers, Resources::CONTENT_MD5);
        $cEncoding  = Utilities::tryGetValue($headers, Resources::CONTENT_ENCODING);
        $cLanguage  = Utilities::tryGetValue($headers, Resources::CONTENT_LANGUAGE);
        $cControl   = Utilities::tryGetValue($headers, Resources::CACHE_CONTROL);
        $etag       = $headers[Resources::ETAG];
        $metadata   = WindowsAzureUtilities::getMetadataArray($headers);
        
        if (array_key_exists(Resources::X_MS_BLOB_SEQUENCE_NUMBER, $headers)) {
            $sNumber = intval($headers[Resources::X_MS_BLOB_SEQUENCE_NUMBER]);
            $properties->setSequenceNumber($sNumber);
        }
        
        $properties->setBlobType($bType);
        $properties->setCacheControl($cControl);
        $properties->setContentEncoding($cEncoding);
        $properties->setContentLanguage($cLanguage);
        $properties->setContentLength($cLength);
        $properties->setContentMD5($cMD5);
        $properties->setContentType($cType);
        $properties->setEtag($etag);<commit_msg>Fix #304<commit_after><?php

/**
 * LICENSE: Licensed under the Apache License, Version 2.0 (the "License")
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 * PHP version 5
 *
 * @category  Microsoft
 * @package   WindowsAzure\Services\Blob\BlobRestProxy
 * @author    <NAME> <<EMAIL>>
 * @copyright 2012 Microsoft Corporation
 * @license   http://www.apache.org/licenses/LICENSE-2.0  Apache License 2.0
 * @link      http://pear.php.net/package/azure-sdk-for-php
 */
 
namespace WindowsAzure\Services\Blob;
use WindowsAzure\Utilities;
use WindowsAzure\Resources;
use WindowsAzure\Validate;
use WindowsAzure\Core\WindowsAzureUtilities;
use WindowsAzure\Services\Core\Models\ServiceProperties;
use WindowsAzure\Services\Core\ServiceRestProxy;
use WindowsAzure\Services\Blob\IBlob;
use WindowsAzure\Services\Blob\Models\BlobServiceOptions;
use WindowsAzure\Services\Core\Models\GetServicePropertiesResult;
use WindowsAzure\Services\Blob\Models\ListContainersOptions;
use WindowsAzure\Services\Blob\Models\ListContainersResult;
use WindowsAzure\Services\Blob\Models\CreateContainerOptions;
use WindowsAzure\Services\Blob\Models\GetContainerPropertiesResult;
use WindowsAzure\Services\Blob\Models\GetContainerAclResult;
use WindowsAzure\Services\Blob\Models\SetContainerMetadataOptions;
use WindowsAzure\Services\Blob\Models\DeleteContainerOptions;
use WindowsAzure\Services\Blob\Models\ListBlobsOptions;
use WindowsAzure\Services\Blob\Models\ListBlobsResult;
use WindowsAzure\Services\Blob\Models\BlobType;
use WindowsAzure\Services\Blob\Models\CreateBlobOptions;
use WindowsAzure\Services\Blob\Models\BlobProperties;
use WindowsAzure\Services\Blob\Models\GetBlobPropertiesOptions;
use WindowsAzure\Services\Blob\Models\GetBlobPropertiesResult;
use WindowsAzure\Services\Blob\Models\SetBlobPropertiesOptions;
use WindowsAzure\Services\Blob\Models\SetBlobPropertiesResult;
use WindowsAzure\Services\Blob\Models\GetBlobMetadataOptions;
use WindowsAzure\Services\Blob\Models\GetBlobMetadataResult;
use WindowsAzure\Services\Blob\Models\SetBlobMetadataOptions;
use WindowsAzure\Services\Blob\Models\SetBlobMetadataResult;
use WindowsAzure\Services\Blob\Models\GetBlobOptions;
use WindowsAzure\Services\Blob\Models\GetBlobResult;
use WindowsAzure\Services\Blob\Models\DeleteBlobOptions;
use WindowsAzure\Services\Blob\Models\LeaseMode;
use WindowsAzure\Services\Blob\Models\AcquireLeaseOptions;
use WindowsAzure\Services\Blob\Models\AcquireLeaseResult;
use WindowsAzure\Services\Blob\Models\CreateBlobPagesOptions;
use WindowsAzure\Services\Blob\Models\CreateBlobPagesResult;
use WindowsAzure\Services\Blob\Models\PageWriteOption;
use WindowsAzure\Services\Blob\Models\ListPageBlobRangesOptions;
use WindowsAzure\Services\Blob\Models\ListPageBlobRangesResult;
use WindowsAzure\Services\Blob\Models\CreateBlobBlockOptions;
use WindowsAzure\Services\Blob\Models\CommitBlobBlocksOptions;
use WindowsAzure\Services\Blob\Models\BlockList;
use WindowsAzure\Services\Blob\Models\ListBlobBlocksOptions;
use WindowsAzure\Services\Blob\Models\ListBlobBlocksResult;
use WindowsAzure\Services\Blob\Models\CopyBlobOptions;
use WindowsAzure\Services\Blob\Models\CreateBlobSnapshotOptions;
use WindowsAzure\Services\Blob\Models\CreateBlobSnapshotResult;

/**
 * This class constructs HTTP requests and receive HTTP responses for blob
 * service layer.
 *
 * @category  Microsoft
 * @package   WindowsAzure\Services\Blob\BlobRestProxy
 * @author    <NAME> <<EMAIL>>
 * @copyright 2012 Microsoft Corporation
 * @license   http://www.apache.org/licenses/LICENSE-2.0  Apache License 2.0
 * @version   Release: @package_version@
 * @link      http://pear.php.net/package/azure-sdk-for-php
 */
class BlobRestProxy extends ServiceRestProxy implements IBlob
{
    /**
     * Creates URI path for blob.
     * 
     * @param string $container The container name.
     * @param string $blob      The blob name.
     * 
     * @return string
     */
    private function _createPath($container, $blob)
    {
        // Empty container means accessing default container
        if (empty($container)) {
            return $blob;
        } else {
            return $container . '/' . $blob;
        }
    }
    
    /**
     * Creates GetBlobPropertiesResult from headers array.
     * 
     * @param array $headers The HTTP response headers array.
     * 
     * @return GetBlobPropertiesResult
     */
    private function _getBlobPropertiesResultFromResponse($headers)
    {
        $result     = new GetBlobPropertiesResult();
        $properties = new BlobProperties();
        $d          = $headers[Resources::LAST_MODIFIED];
        $bType      = $headers[Resources::X_MS_BLOB_TYPE];
        $cLength    = intval($headers[Resources::CONTENT_LENGTH]);
        $lStatus    = Utilities::tryGetValue($headers, Resources::X_MS_LEASE_STATUS);
        $cType      = Utilities::tryGetValue($headers, Resources::CONTENT_TYPE);
        $cMD5       = Utilities::tryGetValue($headers, Resources::CONTENT_MD5);
        $cEncoding  = Utilities::tryGetValue($headers, Resources::CONTENT_ENCODING);
        $cLanguage  = Utilities::tryGetValue($headers, Resources::CONTENT_LANGUAGE);
        $cControl   = Utilities::tryGetValue($headers, Resources::CACHE_CONTROL);
        $etag       = $headers[Resources::ETAG];
        $metadata   = WindowsAzureUtilities::getMetadataArray($headers);
        
        if (array_key_exists(Resources::X_MS_BLOB_SEQUENCE_NUMBER, $headers)) {
            $sNumber = intval($headers[Resources::X_MS_BLOB_SEQUENCE_NUMBER]);
            $properties->setSequenceNumber($sNumber);
        }
        
        $properties->setBlobType($bType);
        $properties->setCacheControl($cControl);
        $properties->setContentEncoding($cEncoding);
        $properties->setContentLanguage($cLanguage);
        $properties->setContentLength($cLength);
        $properties->setContentMD5($cMD5);
        $properties->setContentType($cType);
        $properties->setEtag($etag);
{'fraction_non_alphanumeric': 0.10025847889089058, 'fraction_numerical': 0.004151327641575938, 'mean_word_length': 4.398731501057083, 'pattern_counts': {'":': 0, '<': 17, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 6, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4901190', 'n_tokens_mistral': 3475, 'n_tokens_neox': 3444, 'n_words': 683}