当前位置: 首页>>代码示例>>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;未经允许,请勿转载。