Package com.amazonaws.services.s3.model

Examples of com.amazonaws.services.s3.model.S3Object


    @SuppressWarnings("resource")
    @Override
    public PutObjectResult putObject(PutObjectRequest putObjectRequest) throws AmazonClientException, AmazonServiceException {
        putObjectRequests.add(putObjectRequest);
       
        S3Object s3Object = new S3Object();
        s3Object.setBucketName(putObjectRequest.getBucketName());
        s3Object.setKey(putObjectRequest.getKey());
        if (putObjectRequest.getFile() != null) {
            try {
                s3Object.setObjectContent(new FileInputStream(putObjectRequest.getFile()));
            } catch (FileNotFoundException e) {
                throw new AmazonServiceException("Cannot store the file object.", e);
            }
        } else {
            s3Object.setObjectContent(putObjectRequest.getInputStream());
        }
        objects.add(s3Object);
       
        PutObjectResult putObjectResult = new PutObjectResult();
        putObjectResult.setETag("3a5c8b1ad448bca04584ecb55b836264");
View Full Code Here


    }

    @Override
    public InputStream openInput(String blobName) throws IOException {
        try {
            S3Object s3Object = blobStore.client().getObject(blobStore.bucket(), buildKey(blobName));
            return s3Object.getObjectContent();
        } catch (AmazonS3Exception e) {
            if (e.getStatusCode() == 404) {
                throw new FileNotFoundException(e.getMessage());
            }
            throw e;
View Full Code Here

    protected Queue<Exchange> createExchanges(List<S3ObjectSummary> s3ObjectSummaries) {
        LOG.trace("Received {} messages in this poll", s3ObjectSummaries.size());
       
        Queue<Exchange> answer = new LinkedList<Exchange>();
        for (S3ObjectSummary s3ObjectSummary : s3ObjectSummaries) {
            S3Object s3Object = getAmazonS3Client().getObject(s3ObjectSummary.getBucketName(), s3ObjectSummary.getKey());
            Exchange exchange = getEndpoint().createExchange(s3Object);
            answer.add(exchange);
        }

        return answer;
View Full Code Here

    @Override
    public PutObjectResult putObject(PutObjectRequest putObjectRequest) throws AmazonClientException, AmazonServiceException {
        putObjectRequests.add(putObjectRequest);
       
        S3Object s3Object = new S3Object();
        s3Object.setBucketName(putObjectRequest.getBucketName());
        s3Object.setKey(putObjectRequest.getKey());
        s3Object.setObjectContent(putObjectRequest.getInputStream());
        objects.add(s3Object);
       
        PutObjectResult putObjectResult = new PutObjectResult();
        putObjectResult.setETag("3a5c8b1ad448bca04584ecb55b836264");
        return putObjectResult;
View Full Code Here

        /*
         * TODO: It'd be nice to set the bucket name and key here, but the
         *       information isn't easy to pull out of the response/request
         *       currently.
         */
        S3Object object = new S3Object();
        object.setObjectContent(response.getContent());
        populateObjectMetadata(response, object.getObjectMetadata());

        AmazonWebServiceResponse<S3Object> awsResponse = parseResponseMetadata(response);
        awsResponse.setResult(object);
        return awsResponse;
    }
View Full Code Here

        signRequest(request, HttpMethodName.GET, bucketName, key);
        HttpRequest httpRequest = convertToHttpRequest(request, HttpMethodName.GET);

        try {
            S3ObjectResponseHandler responseHandler = new S3ObjectResponseHandler();
            S3Object s3Object = (S3Object)client.execute(httpRequest, responseHandler, errorResponseHandler);

            /*
             * TODO: For now, it's easiest to set there here in the client, but
             *       we could push this back into the response handler with a
             *       little more work.
             */
            s3Object.setBucketName(bucketName);
            s3Object.setKey(key);

            /*
             * TODO: It'd be nice to check the integrity of the data was received from S3,
             *       but we'd have to read off the stream and buffer the contents somewhere
             *       in order to do that.
View Full Code Here

    public ObjectMetadata getObject(GetObjectRequest getObjectRequest, File destinationFile)
            throws AmazonClientException, AmazonServiceException {
        assertParameterNotNull(destinationFile,
                "The destination file parameter must be specified when downloading an object directly to a file");

        S3Object s3Object = getObject(getObjectRequest);
        // getObject can return null if constraints were specified but not met
        if (s3Object == null) return null;

        OutputStream outputStream = null;
        try {
            outputStream = new BufferedOutputStream(new FileOutputStream(destinationFile));
            byte[] buffer = new byte[1024*10];
            int bytesRead;
            while ((bytesRead = s3Object.getObjectContent().read(buffer)) > -1) {
                outputStream.write(buffer, 0, bytesRead);
            }
        } catch (IOException e) {
            throw new AmazonClientException(
                    "Unable to store object contents to disk: " + e.getMessage(), e);
        } finally {
            try {outputStream.close();} catch (Exception e) {}
            try {s3Object.getObjectContent().close();} catch (Exception e) {}
        }

        try {
            byte[] clientSideHash = ServiceUtils.computeMD5Hash(new FileInputStream(destinationFile));
            byte[] serverSideHash = ServiceUtils.fromHex(s3Object.getObjectMetadata().getETag());

            if (!Arrays.equals(clientSideHash, serverSideHash)) {
                throw new AmazonClientException("Unable to verify integrity of data download.  " +
                        "Client calculated content hash didn't match hash calculated by Amazon S3.  " +
                        "The data stored in '" + destinationFile.getAbsolutePath() + "' may be corrupt.");
            }
        } catch (Exception e) {
            log.warn("Unable to calculate MD5 hash to validate download: " + e.getMessage(), e);
        }

        return s3Object.getObjectMetadata();
    }
View Full Code Here

                                 throw new AmazonClientException("Couldn't wait for setting future into the monitor");
                             }
                         }
                     }
                    download.setState(TransferState.InProgress);
                    S3Object s3Object = ServiceUtils.retryableDownloadS3ObjectToFile(file, new ServiceUtils.RetryableS3DownloadTask() {
                       
                        @Override
                        public S3Object getS3ObjectStream() {
                            S3Object s3Object = s3.getObject(getObjectRequest);
                            download.setS3Object(s3Object);
                            return s3Object;
                        }
                       
                        @Override
View Full Code Here

  public void retrieveProduct(Product product, File directory) throws DataTransferException,
      IOException {
    for (Reference ref : product.getProductReferences()) {
      GetObjectRequest request = new GetObjectRequest(bucketName, stripProtocol(
          ref.getDataStoreReference(), true));
      S3Object file = s3Client.getObject(request);
      stageFile(file, ref, directory);
    }
  }
View Full Code Here

    @Override public void readBlob(final String blobName, final ReadBlobListener listener) {
        blobStore.executor().execute(new Runnable() {
            @Override public void run() {
                InputStream is;
                try {
                    S3Object object = blobStore.client().getObject(blobStore.bucket(), buildKey(blobName));
                    is = object.getObjectContent();
                } catch (Exception e) {
                    listener.onFailure(e);
                    return;
                }
                byte[] buffer = new byte[blobStore.bufferSizeInBytes()];
View Full Code Here

TOP

Related Classes of com.amazonaws.services.s3.model.S3Object

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.