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


Java StreamMd5AndLength類代碼示例

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


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

示例1: uploadBlock

import com.microsoft.azure.storage.core.StreamMd5AndLength; //導入依賴的package包/類
/**
 * Uploads a block to be committed as part of the block blob, using the specified block ID, the specified lease ID,
 * request options, and operation context.
 * 
 * @param blockId
 *            A <code>String</code> that represents the Base-64 encoded block ID. Note for a given blob the length
 *            of all Block IDs must be identical.
 * @param sourceStream
 *            An {@link InputStream} object that represents the input stream to write to the block 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 that 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 that 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.
 * 
 * @throws IOException
 *             If an I/O error occurred.
 * @throws StorageException
 *             If a storage service error occurred.
 */
@DoesServiceRequest
public void uploadBlock(final String blockId, 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.BLOCK_BLOB, this.blobServiceClient);

    // Assert block length
    if (Utility.isNullOrEmpty(blockId) || !Base64.validateIsBase64String(blockId)) {
        throw new IllegalArgumentException(SR.INVALID_BLOCK_ID);
    }

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

    this.uploadBlockInternal(blockId, descriptor.getMd5(), bufferedStreamReference, descriptor.getLength(),
            accessCondition, options, opContext);
}
 
開發者ID:Azure,項目名稱:azure-storage-android,代碼行數:80,代碼來源:CloudBlockBlob.java

示例2: appendBlock

import com.microsoft.azure.storage.core.StreamMd5AndLength; //導入依賴的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

示例3: appendBlock

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