Example usage for com.amazonaws.services.s3.model UploadPartRequest setInputStream

List of usage examples for com.amazonaws.services.s3.model UploadPartRequest setInputStream

Introduction

In this page you can find the example usage for com.amazonaws.services.s3.model UploadPartRequest setInputStream.

Prototype

@Override
public void setInputStream(InputStream inputStream) 

Source Link

Document

Sets the stream containing the data to upload for the new part.

Usage

From source file:c3.ops.priam.aws.S3PartUploader.java

License:Apache License

private Void uploadPart() throws AmazonClientException, BackupRestoreException {
    UploadPartRequest req = new UploadPartRequest();
    req.setBucketName(dataPart.getBucketName());
    req.setKey(dataPart.getS3key());// w  ww  .j  a  v  a 2 s  . com
    req.setUploadId(dataPart.getUploadID());
    req.setPartNumber(dataPart.getPartNo());
    req.setPartSize(dataPart.getPartData().length);
    req.setMd5Digest(SystemUtils.toBase64(dataPart.getMd5()));
    req.setInputStream(new ByteArrayInputStream(dataPart.getPartData()));
    UploadPartResult res = client.uploadPart(req);
    PartETag partETag = res.getPartETag();
    if (!partETag.getETag().equals(SystemUtils.toHex(dataPart.getMd5())))
        throw new BackupRestoreException("Unable to match MD5 for part " + dataPart.getPartNo());
    partETags.add(partETag);
    return null;
}

From source file:com.eucalyptus.objectstorage.providers.s3.S3ProviderClient.java

License:Open Source License

@Override
public UploadPartResponseType uploadPart(UploadPartType request, InputStream dataContent) throws S3Exception {
    String bucketName = request.getBucket();
    String key = request.getKey();

    User requestUser = getRequestUser(request);
    OsgInternalS3Client internalS3Client = null;
    try {//w w w. j  a  v a2 s  .c  om
        internalS3Client = getS3Client(requestUser);
        AmazonS3Client s3Client = internalS3Client.getS3Client();

        UploadPartResult result;
        UploadPartRequest uploadPartRequest = new UploadPartRequest();
        uploadPartRequest.setBucketName(bucketName);
        uploadPartRequest.setKey(key);
        uploadPartRequest.setInputStream(dataContent);
        uploadPartRequest.setUploadId(request.getUploadId());
        uploadPartRequest.setPartNumber(Integer.valueOf(request.getPartNumber()));
        uploadPartRequest.setMd5Digest(request.getContentMD5());
        uploadPartRequest.setPartSize(Long.valueOf(request.getContentLength()));
        try {
            result = s3Client.uploadPart(uploadPartRequest);
        } catch (AmazonServiceException e) {
            LOG.debug("Error from backend", e);
            throw S3ExceptionMapper.fromAWSJavaSDK(e);
        }
        UploadPartResponseType reply = request.getReply();
        reply.setEtag(result.getETag());
        reply.setLastModified(new Date());
        return reply;
    } catch (AmazonServiceException e) {
        LOG.debug("Error from backend", e);
        throw S3ExceptionMapper.fromAWSJavaSDK(e);
    }
}

From source file:com.netflix.exhibitor.core.backup.s3.S3BackupProvider.java

License:Apache License

private PartETag uploadChunk(byte[] buffer, int bytesRead, InitiateMultipartUploadResult initResponse,
        int index) throws Exception {
    byte[] md5 = S3Utils.md5(buffer, bytesRead);

    UploadPartRequest request = new UploadPartRequest();
    request.setBucketName(initResponse.getBucketName());
    request.setKey(initResponse.getKey());
    request.setUploadId(initResponse.getUploadId());
    request.setPartNumber(index);//from   w  w w.  j a  va  2 s  .c o  m
    request.setPartSize(bytesRead);
    request.setMd5Digest(S3Utils.toBase64(md5));
    request.setInputStream(new ByteArrayInputStream(buffer, 0, bytesRead));

    UploadPartResult response = s3Client.uploadPart(request);
    PartETag partETag = response.getPartETag();
    if (!response.getPartETag().getETag().equals(S3Utils.toHex(md5))) {
        throw new Exception("Unable to match MD5 for part " + index);
    }

    return partETag;
}

From source file:com.upplication.s3fs.S3OutputStream.java

License:Open Source License

private void uploadPart(final InputStream content, final long contentLength, final byte[] checksum,
        final int partNumber, final boolean lastPart) throws IOException {

    if (aborted)//from   w ww.j  a  va  2  s .  c  o  m
        return;

    final UploadPartRequest request = new UploadPartRequest();
    request.setBucketName(objectId.getBucket());
    request.setKey(objectId.getKey());
    request.setUploadId(uploadId);
    request.setPartNumber(partNumber);
    request.setPartSize(contentLength);
    request.setInputStream(content);
    request.setLastPart(lastPart);
    request.setMd5Digest(Base64.encodeAsString(checksum));

    final PartETag partETag = s3.uploadPart(request).getPartETag();
    log.trace("Uploaded part {} with length {} for {}: {}", partETag.getPartNumber(), contentLength, objectId,
            partETag.getETag());
    partETags.add(partETag);

}

From source file:eu.stratosphere.nephele.fs.s3.S3DataOutputStream.java

License:Apache License

private void uploadPartAndFlushBuffer() throws IOException {

    boolean operationSuccessful = false;

    if (this.uploadId == null) {
        this.uploadId = initiateMultipartUpload();
    }// ww w.j a v a2 s  .c  om

    try {

        if (this.partNumber >= MAX_PART_NUMBER) {
            throw new IOException("Cannot upload any more data: maximum part number reached");
        }

        final InputStream inputStream = new InternalUploadInputStream(this.buf, this.bytesWritten);
        final UploadPartRequest request = new UploadPartRequest();
        request.setBucketName(this.bucket);
        request.setKey(this.object);
        request.setInputStream(inputStream);
        request.setUploadId(this.uploadId);
        request.setPartSize(this.bytesWritten);
        request.setPartNumber(this.partNumber++);

        final UploadPartResult result = this.s3Client.uploadPart(request);
        this.partETags.add(result.getPartETag());

        this.bytesWritten = 0;
        operationSuccessful = true;

    } catch (AmazonServiceException e) {
        throw new IOException(StringUtils.stringifyException(e));
    } finally {
        if (!operationSuccessful) {
            abortUpload();
        }
    }
}