當前位置: 首頁>>代碼示例>>Java>>正文


Java StorageRequest類代碼示例

本文整理匯總了Java中com.microsoft.azure.storage.core.StorageRequest的典型用法代碼示例。如果您正苦於以下問題:Java StorageRequest類的具體用法?Java StorageRequest怎麽用?Java StorageRequest使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


StorageRequest類屬於com.microsoft.azure.storage.core包,在下文中一共展示了StorageRequest類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: parseErrorDetails

import com.microsoft.azure.storage.core.StorageRequest; //導入依賴的package包/類
/**
 * Parse the table extended error information from the response body.
 * 
 * @param request
 *            the request whose body to examine for the error information.
 * @return The {@link StorageExtendedErrorInformation} parsed from the body or null if parsing fails or the request
 *         contains no body.
 */
public static StorageExtendedErrorInformation parseErrorDetails(StorageRequest<CloudTableClient, ?, ?> request) {
    try {
        if (request == null || request.getConnection().getErrorStream() == null) {
            return null;
        }

        return getExtendedErrorInformation(new InputStreamReader(
        		request.getConnection().getErrorStream()), 
        		TablePayloadFormat.Json);
    } catch (Exception e) {
        return null;
    }
}
 
開發者ID:Azure,項目名稱:azure-storage-android,代碼行數:22,代碼來源:TableStorageErrorDeserializer.java

示例2: translateException

import com.microsoft.azure.storage.core.StorageRequest; //導入依賴的package包/類
/**
 * RESERVED FOR INTERNAL USE. Translates the specified exception into a storage exception.
 * 
 * @param request
 *            An <code>HttpURLConnection</code> object that represents the request whose exception is being
 *            translated.
 * @param cause
 *            An <code>Exception</code> object that represents the exception to translate.
 * 
 * @return A <code>StorageException</code> object that represents translated exception.
 */
public static StorageException translateException(final StorageRequest<?, ?, ?> request, final Exception cause,
        final OperationContext opContext) {
    if (request == null || request.getConnection() == null) {
        return translateClientException(cause);
    }
    
    if (cause instanceof SocketException) {
        String message = cause == null ? Constants.EMPTY_STRING : cause.getMessage();
        return new StorageException(StorageErrorCode.SERVICE_INTERNAL_ERROR.toString(),
                "An unknown failure occurred : ".concat(message), HttpURLConnection.HTTP_INTERNAL_ERROR,
                null, cause);
    }

    StorageException translatedException = null;

    String responseMessage = null;
    int responseCode = 0;
    try {
        responseCode = request.getConnection().getResponseCode();
        responseMessage = request.getConnection().getResponseMessage();
    } catch (final IOException e) {
        // ignore errors
    }

    if (responseMessage == null) {
        responseMessage = Constants.EMPTY_STRING;
    }

    StorageExtendedErrorInformation extendedError = request.parseErrorDetails();
    translatedException = new StorageException(request.getResult().getErrorCode(), responseMessage,
            responseCode, extendedError, cause);

    Utility.logHttpError(translatedException, opContext);
    return translatedException;
}
 
開發者ID:Azure,項目名稱:azure-storage-java,代碼行數:47,代碼來源:StorageException.java

示例3: parseErrorDetails

import com.microsoft.azure.storage.core.StorageRequest; //導入依賴的package包/類
/**
 * Parse the table extended error information from the response body.
 * 
 * @param request
 *            the request whose body to examine for the error information.
 * @return The {@link StorageExtendedErrorInformation} parsed from the body or null if parsing fails or the request
 *         contains no body.
 */
public static StorageExtendedErrorInformation parseErrorDetails(StorageRequest<CloudTableClient, ?, ?> request) {
    try {
        if (request == null || request.getConnection().getErrorStream() == null) {
            return null;
        }

        return getExtendedErrorInformation(new InputStreamReader(request.getConnection().getErrorStream()), TablePayloadFormat.Json);
    } catch (Exception e) {
        return null;
    }
}
 
開發者ID:Azure,項目名稱:azure-storage-java,代碼行數:20,代碼來源:TableStorageErrorDeserializer.java

示例4: preProcessDownloadResponse

import com.microsoft.azure.storage.core.StorageRequest; //導入依賴的package包/類
private Integer preProcessDownloadResponse(final StorageRequest<CloudBlobClient, CloudBlob, Integer> request,
        final BlobRequestOptions options, final CloudBlobClient client, final CloudBlob blob,
        final OperationContext context, final boolean isRangeGet) throws StorageException, URISyntaxException,
        ParseException {
    if (request.getResult().getStatusCode() != HttpURLConnection.HTTP_PARTIAL
            && request.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) {
        request.setNonExceptionedRetryableFailure(true);
        return null;
    }

    if (!request.getArePropertiesPopulated()) {
        String originalContentMD5 = null;

        final BlobAttributes retrievedAttributes = BlobResponse.getBlobAttributes(request.getConnection(),
                blob.getStorageUri(), blob.snapshotID);

        // Do not update Content-MD5 if it is a range get.
        if (isRangeGet) {
            originalContentMD5 = blob.properties.getContentMD5();
        }
        else {
            originalContentMD5 = retrievedAttributes.getProperties().getContentMD5();
        }

        if (!options.getDisableContentMD5Validation() && options.getUseTransactionalContentMD5()
                && Utility.isNullOrEmpty(retrievedAttributes.getProperties().getContentMD5())) {
            throw new StorageException(StorageErrorCodeStrings.MISSING_MD5_HEADER, SR.MISSING_MD5,
                    Constants.HeaderConstants.HTTP_UNUSED_306, null, null);
        }

        blob.properties = retrievedAttributes.getProperties();
        blob.metadata = retrievedAttributes.getMetadata();
        request.setContentMD5(retrievedAttributes.getProperties().getContentMD5());
        blob.properties.setContentMD5(originalContentMD5);
        request.setLockedETag(blob.properties.getEtag());
        request.setArePropertiesPopulated(true);
    }

    // If the download fails and Get Blob needs to resume the download, going to the
    // same storage location is important to prevent a possible ETag mismatch.
    request.setRequestLocationMode(request.getResult().getTargetLocation() == StorageLocation.PRIMARY ? RequestLocationMode.PRIMARY_ONLY
            : RequestLocationMode.SECONDARY_ONLY);
    return null;
}
 
開發者ID:horizon-institute,項目名稱:runspotrun-android-client,代碼行數:45,代碼來源:CloudBlob.java

示例5: preProcessDownloadResponse

import com.microsoft.azure.storage.core.StorageRequest; //導入依賴的package包/類
private Integer preProcessDownloadResponse(final StorageRequest<CloudFileClient, CloudFile, Integer> request,
        final FileRequestOptions options, final CloudFileClient client, final CloudFile file,
        final OperationContext context, final boolean isRangeGet) throws StorageException {
    if (request.getResult().getStatusCode() != HttpURLConnection.HTTP_PARTIAL
            && request.getResult().getStatusCode() != HttpURLConnection.HTTP_OK) {
        request.setNonExceptionedRetryableFailure(true);
        return null;
    }

    if (!request.getArePropertiesPopulated()) {
        String originalContentMD5 = null;

        final FileAttributes retrievedAttributes = FileResponse.getFileAttributes(request.getConnection(),
                file.getStorageUri());

        // Do not update Content-MD5 if it is a range get. 
        if (isRangeGet) {
            originalContentMD5 = file.properties.getContentMD5();
        }
        else {
            originalContentMD5 = retrievedAttributes.getProperties().getContentMD5();
        }

        if (!options.getDisableContentMD5Validation() && options.getUseTransactionalContentMD5()
                && Utility.isNullOrEmpty(retrievedAttributes.getProperties().getContentMD5())) {
            throw new StorageException(StorageErrorCodeStrings.MISSING_MD5_HEADER, SR.MISSING_MD5,
                    Constants.HeaderConstants.HTTP_UNUSED_306, null, null);
        }

        file.properties = retrievedAttributes.getProperties();
        file.metadata = retrievedAttributes.getMetadata();
        request.setContentMD5(retrievedAttributes.getProperties().getContentMD5());
        file.properties.setContentMD5(originalContentMD5);
        request.setLockedETag(file.properties.getEtag());
        request.setArePropertiesPopulated(true);
    }
    else {
        if (request.getLockedETag() != null) {
            if (!request.getLockedETag().equals(file.properties.getEtag())) {
                throw new StorageException(StorageErrorCode.CONDITION_FAILED.toString(),
                        SR.INVALID_CONDITIONAL_HEADERS, HttpURLConnection.HTTP_PRECON_FAILED, null, null);
            }
        }
    }

    // If the download fails and Get File needs to resume the download, going to the
    // same storage location is important to prevent a possible ETag mismatch.
    request.setRequestLocationMode(request.getResult().getTargetLocation() == StorageLocation.PRIMARY ? RequestLocationMode.PRIMARY_ONLY
            : RequestLocationMode.SECONDARY_ONLY);
    return null;
}
 
開發者ID:horizon-institute,項目名稱:runspotrun-android-client,代碼行數:52,代碼來源:CloudFile.java

示例6: translateException

import com.microsoft.azure.storage.core.StorageRequest; //導入依賴的package包/類
/**
 * RESERVED FOR INTERNAL USE. Translates the specified exception into a storage exception.
 * 
 * @param request
 *            An <code>HttpURLConnection</code> object that represents the request whose exception is being
 *            translated.
 * @param cause
 *            An <code>Exception</code> object that represents the exception to translate.
 * 
 * @return A <code>StorageException</code> object that represents translated exception.
 */
public static StorageException translateException(final StorageRequest<?, ?, ?> request, final Exception cause,
        final OperationContext opContext) {
    if (request == null || request.getConnection() == null) {
        return translateClientException(cause);
    }
    
    if (cause instanceof SocketException) {
        String message = cause == null ? Constants.EMPTY_STRING : cause.getMessage();
        return new StorageException(StorageErrorCode.SERVICE_INTERNAL_ERROR.toString(),
                "An unknown failure occurred : ".concat(message), HttpURLConnection.HTTP_INTERNAL_ERROR,
                null, cause);
    }

    StorageException translatedException = null;

    String responseMessage = null;
    int responseCode = 0;
    try {
        responseCode = request.getConnection().getResponseCode();
        responseMessage = request.getConnection().getResponseMessage();
    } catch (final IOException e) {
        // ignore errors
    }

    if (responseMessage == null) {
        responseMessage = Constants.EMPTY_STRING;
    }

    StorageExtendedErrorInformation extendedError = request.parseErrorDetails();
    if (extendedError != null) {
        // 1. If extended information is available use it
        translatedException = new StorageException(extendedError.getErrorCode(), responseMessage, responseCode,
                extendedError, cause);
    } else {
        // 2. If extended information is unavailable, translate exception based
        // on status code
        translatedException = translateFromHttpStatus(responseCode, responseMessage, cause);   
    }

    if (translatedException != null) {
        Utility.logHttpError(translatedException, opContext);
        return translatedException;
    } else {
        return new StorageException(StorageErrorCode.SERVICE_INTERNAL_ERROR.toString(),
                "The server encountered an unknown failure: ".concat(responseMessage),
                HttpURLConnection.HTTP_INTERNAL_ERROR, null, cause);   
    }
}
 
開發者ID:Azure,項目名稱:azure-storage-android,代碼行數:60,代碼來源:StorageException.java

示例7: appendBlock

import com.microsoft.azure.storage.core.StorageRequest; //導入依賴的package包/類
/**
 * Commits a new block of data to the end of the blob.
 * 
 * @param sourceStream
 *            An {@link InputStream} object that represents the input stream to write to the Append blob.
 * @param length
 *            A <code>long</code> which represents the length, in bytes, of the stream data, or -1 if unknown.
 * @param accessCondition
 *            An {@link AccessCondition} object which represents the access conditions for the blob.
 * @param options
 *            A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying
 *            <code>null</code> will use the default request options from the associated service client (
 *            {@link CloudBlobClient}).
 * @param opContext
 *            An {@link OperationContext} object which represents the context for the current operation. This object
 *            is used to track requests to the storage service, and to provide additional runtime information about
 *            the operation.
 * @return The offset at which the block was appended.</returns>
 * @throws IOException
 *             If an I/O exception occurred.
 * @throws StorageException
 *             If a storage service error occurred.
 */
@DoesServiceRequest
public Long appendBlock(final InputStream sourceStream, final long length, final AccessCondition accessCondition, 
        BlobRequestOptions options, OperationContext opContext) throws StorageException, IOException
{
    if (length < -1) {
        throw new IllegalArgumentException(SR.STREAM_LENGTH_NEGATIVE);
    }

    assertNoWriteOperationForSnapshot();

    if (opContext == null) {
        opContext = new OperationContext();
    }

    options = BlobRequestOptions.populateAndApplyDefaults(options, BlobType.APPEND_BLOB, this.blobServiceClient);

    if (sourceStream.markSupported()) {
        // Mark sourceStream for current position.
        sourceStream.mark(Constants.MAX_MARK_LENGTH);
    }

    InputStream bufferedStreamReference = sourceStream;
    StreamMd5AndLength descriptor = new StreamMd5AndLength();
    descriptor.setLength(length);

    if (!sourceStream.markSupported()) {
        // needs buffering
        final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        descriptor = Utility.writeToOutputStream(sourceStream, byteStream, length, false /* rewindSourceStream */,
                options.getUseTransactionalContentMD5(), opContext, options);

        bufferedStreamReference = new ByteArrayInputStream(byteStream.toByteArray());
    }
    else if (length < 0 || options.getUseTransactionalContentMD5()) {
        // If the stream is of unknown length or we need to calculate the
        // MD5, then we we need to read the stream contents first
        descriptor = Utility.analyzeStream(sourceStream, length, -1L, true /* rewindSourceStream */,
                options.getUseTransactionalContentMD5());
    }

    if (descriptor.getLength() > 4 * Constants.MB) {
        throw new IllegalArgumentException(SR.STREAM_LENGTH_GREATER_THAN_4MB);
    }

    StorageRequest<CloudBlobClient, CloudAppendBlob, Long> appendBlockImpl = appendBlockImpl(descriptor.getMd5(), bufferedStreamReference, 
            descriptor.getLength(), accessCondition, options, opContext);
    return ExecutionEngine.executeWithRetry(this.blobServiceClient, this, appendBlockImpl, options.getRetryPolicyFactory(), opContext);
}
 
開發者ID:Azure,項目名稱:azure-storage-android,代碼行數:72,代碼來源:CloudAppendBlob.java

示例8: appendBlock

import com.microsoft.azure.storage.core.StorageRequest; //導入依賴的package包/類
/**
 * Commits a new block of data to the end of the blob.
 * 
 * @param sourceStream
 *            An {@link InputStream} object that represents the input stream to write to the Append blob.
 * @param length
 *            A <code>long</code> which represents the length, in bytes, of the stream data, or -1 if unknown.
 * @param accessCondition
 *            An {@link AccessCondition} object which represents the access conditions for the blob.
 * @param options
 *            A {@link BlobRequestOptions} object that specifies any additional options for the request. Specifying
 *            <code>null</code> will use the default request options from the associated service client (
 *            {@link CloudBlobClient}).
 * @param opContext
 *            An {@link OperationContext} object which represents the context for the current operation. This object
 *            is used to track requests to the storage service, and to provide additional runtime information about
 *            the operation.
 * @return The offset at which the block was appended.
 * @throws IOException
 *             If an I/O exception occurred.
 * @throws StorageException
 *             If a storage service error occurred.
 */
@DoesServiceRequest
public Long appendBlock(final InputStream sourceStream, final long length, final AccessCondition accessCondition, 
        BlobRequestOptions options, OperationContext opContext) throws StorageException, IOException
{
    if (length < -1) {
        throw new IllegalArgumentException(SR.STREAM_LENGTH_NEGATIVE);
    }

    assertNoWriteOperationForSnapshot();

    if (opContext == null) {
        opContext = new OperationContext();
    }

    options = BlobRequestOptions.populateAndApplyDefaults(options, BlobType.APPEND_BLOB, this.blobServiceClient);

    // Assert no encryption policy as this is not supported for partial uploads
    options.assertNoEncryptionPolicyOrStrictMode();
    
    if (sourceStream.markSupported()) {
        // Mark sourceStream for current position.
        sourceStream.mark(Constants.MAX_MARK_LENGTH);
    }

    InputStream bufferedStreamReference = sourceStream;
    StreamMd5AndLength descriptor = new StreamMd5AndLength();
    descriptor.setLength(length);

    if (!sourceStream.markSupported()) {
        // needs buffering
        final ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
        descriptor = Utility.writeToOutputStream(sourceStream, byteStream, length, false /* rewindSourceStream */,
                options.getUseTransactionalContentMD5(), opContext, options);

        bufferedStreamReference = new ByteArrayInputStream(byteStream.toByteArray());
    }
    else if (length < 0 || options.getUseTransactionalContentMD5()) {
        // If the stream is of unknown length or we need to calculate the
        // MD5, then we we need to read the stream contents first
        descriptor = Utility.analyzeStream(sourceStream, length, -1L, true /* rewindSourceStream */,
                options.getUseTransactionalContentMD5());
    }

    if (descriptor.getLength() > 4 * Constants.MB) {
        throw new IllegalArgumentException(SR.STREAM_LENGTH_GREATER_THAN_4MB);
    }

    StorageRequest<CloudBlobClient, CloudAppendBlob, Long> appendBlockImpl = appendBlockImpl(descriptor.getMd5(), bufferedStreamReference, 
            descriptor.getLength(), accessCondition, options, opContext);
    return ExecutionEngine.executeWithRetry(this.blobServiceClient, this, appendBlockImpl, options.getRetryPolicyFactory(), opContext);
}
 
開發者ID:Azure,項目名稱:azure-storage-java,代碼行數:75,代碼來源:CloudAppendBlob.java


注:本文中的com.microsoft.azure.storage.core.StorageRequest類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。