当前位置: 首页>>代码示例>>Java>>正文


Java UploadPartRequest.getInputStream方法代码示例

本文整理汇总了Java中com.amazonaws.services.s3.model.UploadPartRequest.getInputStream方法的典型用法代码示例。如果您正苦于以下问题:Java UploadPartRequest.getInputStream方法的具体用法?Java UploadPartRequest.getInputStream怎么用?Java UploadPartRequest.getInputStream使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.amazonaws.services.s3.model.UploadPartRequest的用法示例。


在下文中一共展示了UploadPartRequest.getInputStream方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: computeLastPartSize

import com.amazonaws.services.s3.model.UploadPartRequest; //导入方法依赖的package包/类
@Override
final long computeLastPartSize(UploadPartRequest request) {
    long plaintextLength;
    if (request.getFile() != null) {
        if (request.getPartSize() > 0)
            plaintextLength = request.getPartSize();
        else
            plaintextLength = request.getFile().length();
    } else if (request.getInputStream() != null) {
        plaintextLength = request.getPartSize();
    } else {
        return -1;
    }
    long cipherBlockSize = contentCryptoScheme.getBlockSizeInBytes();
    long offset = cipherBlockSize - (plaintextLength % cipherBlockSize);
    return plaintextLength + offset;
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:18,代码来源:S3CryptoModuleEO.java

示例2: uploadPartsInSeries

import com.amazonaws.services.s3.model.UploadPartRequest; //导入方法依赖的package包/类
/**
 * Uploads all parts in the request in serial in this thread, then completes
 * the upload and returns the result.
 */
private UploadResult uploadPartsInSeries(UploadPartRequestFactory requestFactory) {

    final List<PartETag> partETags = new ArrayList<PartETag>();

    while (requestFactory.hasMoreRequests()) {
        if (threadPool.isShutdown()) throw new CancellationException("TransferManager has been shutdown");
        UploadPartRequest uploadPartRequest = requestFactory.getNextUploadPartRequest();
        // Mark the stream in case we need to reset it
        InputStream inputStream = uploadPartRequest.getInputStream();
        if (inputStream != null && inputStream.markSupported()) {
            if (uploadPartRequest.getPartSize() >= Integer.MAX_VALUE) {
                inputStream.mark(Integer.MAX_VALUE);
            } else {
                inputStream.mark((int)uploadPartRequest.getPartSize());
            }
        }
        partETags.add(s3.uploadPart(uploadPartRequest).getPartETag());
    }

    CompleteMultipartUploadRequest req =
        new CompleteMultipartUploadRequest(
            origReq.getBucketName(), origReq.getKey(), multipartUploadId,
                partETags)
                .withRequesterPays(origReq.isRequesterPays())
        .withGeneralProgressListener(origReq.getGeneralProgressListener())
        .withRequestMetricCollector(origReq.getRequestMetricCollector())
        ;
    CompleteMultipartUploadResult res = s3.completeMultipartUpload(req);

    UploadResult uploadResult = new UploadResult();
    uploadResult.setBucketName(res.getBucketName());
    uploadResult.setKey(res.getKey());
    uploadResult.setETag(res.getETag());
    uploadResult.setVersionId(res.getVersionId());
    return uploadResult;
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:41,代码来源:UploadCallable.java

示例3: newMultipartS3CipherInputStream

import com.amazonaws.services.s3.model.UploadPartRequest; //导入方法依赖的package包/类
protected final CipherLiteInputStream newMultipartS3CipherInputStream(
        UploadPartRequest req, CipherLite cipherLite) {
    final File fileOrig = req.getFile();
    final InputStream isOrig = req.getInputStream();
    InputStream isCurr = null;
    try {
        if (fileOrig == null) {
            if (isOrig == null) {
                throw new IllegalArgumentException(
                    "A File or InputStream must be specified when uploading part");
            }
            isCurr = isOrig;
        } else {
            isCurr = new ResettableInputStream(fileOrig);
        }
        isCurr = new InputSubstream(isCurr,
                req.getFileOffset(),
                req.getPartSize(),
                req.isLastPart());
        return cipherLite.markSupported()
             ? new CipherLiteInputStream(isCurr, cipherLite,
                   DEFAULT_BUFFER_SIZE,
                   IS_MULTI_PART, req.isLastPart())
             : new RenewableCipherLiteInputStream(isCurr, cipherLite,
                    DEFAULT_BUFFER_SIZE,
                    IS_MULTI_PART, req.isLastPart());
    } catch (Exception e) {
        cleanupDataSource(req, fileOrig, isOrig, isCurr, log);
        throw failure(e,"Unable to create cipher input stream");
    }
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:32,代码来源:S3CryptoModuleBase.java

示例4: uploadPartSecurely

import com.amazonaws.services.s3.model.UploadPartRequest; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 *
 * <p>
 * <b>NOTE:</b> Because the encryption process requires context from
 * previous blocks, parts uploaded with the AmazonS3EncryptionClient (as
 * opposed to the normal AmazonS3Client) must be uploaded serially, and in
 * order. Otherwise, the previous encryption context isn't available to use
 * when encrypting the current part.
 */
@Override
public UploadPartResult uploadPartSecurely(UploadPartRequest req) {
    appendUserAgent(req, USER_AGENT);
    final int blockSize = contentCryptoScheme.getBlockSizeInBytes();
    final boolean isLastPart = req.isLastPart();
    final String uploadId = req.getUploadId();
    final long partSize = req.getPartSize();
    final boolean partSizeMultipleOfCipherBlockSize = 0 == (partSize % blockSize);
    if (!isLastPart && !partSizeMultipleOfCipherBlockSize) {
        throw new SdkClientException(
            "Invalid part size: part sizes for encrypted multipart uploads must be multiples "
                + "of the cipher block size ("
                + blockSize
                + ") with the exception of the last part.");
    }
    final T uploadContext = multipartUploadContexts.get(uploadId);
    if (uploadContext == null) {
        throw new SdkClientException(
            "No client-side information available on upload ID " + uploadId);
    }
    final UploadPartResult result;
    // Checks the parts are uploaded in series
    uploadContext.beginPartUpload(req.getPartNumber());
    CipherLite cipherLite = cipherLiteForNextPart(uploadContext);
    final File fileOrig = req.getFile();
    final InputStream isOrig = req.getInputStream();
    SdkFilterInputStream isCurr = null;
    try {
        CipherLiteInputStream clis = newMultipartS3CipherInputStream(req, cipherLite);
        isCurr = clis; // so the clis will be closed (in the finally block below) upon
                   // unexpected failure should we opened a file undereath
        isCurr = wrapForMultipart(clis, partSize);
        req.setInputStream(isCurr);
        // Treat all encryption requests as input stream upload requests,
        // not as file upload requests.
        req.setFile(null);
        req.setFileOffset(0);
        // The last part of the multipart upload will contain an extra
        // 16-byte mac
        if (isLastPart) {
            // We only change the size of the last part
            long lastPartSize = computeLastPartSize(req);
            if (lastPartSize > -1)
                req.setPartSize(lastPartSize);
            if (uploadContext.hasFinalPartBeenSeen()) {
                throw new SdkClientException(
                    "This part was specified as the last part in a multipart upload, but a previous part was already marked as the last part.  "
                  + "Only the last part of the upload should be marked as the last part.");
            }
        }

        result = s3.uploadPart(req);
    } finally {
        cleanupDataSource(req, fileOrig, isOrig, isCurr, log);
        uploadContext.endPartUpload();
    }
    if (isLastPart)
        uploadContext.setHasFinalPartBeenSeen(true);
    updateUploadContext(uploadContext, isCurr);
    return result;
}
 
开发者ID:IBM,项目名称:ibm-cos-sdk-java,代码行数:72,代码来源:S3CryptoModuleBase.java


注:本文中的com.amazonaws.services.s3.model.UploadPartRequest.getInputStream方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。