Package com.amazonaws.services.s3.model

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


     *       get access to all the visible variables at the calling site of this method.
     */
    public static S3Object retryableDownloadS3ObjectToFile (File file, RetryableS3DownloadTask retryableS3DownloadTask) {
        boolean hasRetried = false;
        boolean needRetry;
        S3Object s3Object;
        do {
            needRetry = false;
            s3Object = retryableS3DownloadTask.getS3ObjectStream();
            if ( s3Object == null )
                return null;

            try {
                ServiceUtils.downloadObjectToFile(s3Object, file, retryableS3DownloadTask.needIntegrityCheck());
            } catch (AmazonClientException ace) {
                // Determine whether an immediate retry is needed according to the captured AmazonClientException.
                // (There are three cases when downloadObjectToFile() throws AmazonClientException:
                //     1) SocketException or SSLProtocolException when writing to disk (e.g. when user aborts the download)
                //    2) Other IOException when writing to disk
                //    3) MD5 hashes don't match
                // The current code will retry the download only when case 2) or 3) happens.
                if (ace.getCause() instanceof SocketException || ace.getCause() instanceof SSLProtocolException) {
                    throw ace;
                } else {
                    needRetry = true;
                    if ( hasRetried )
                        throw ace;
                    else {
                        log.info("Retry the download of object " + s3Object.getKey() + " (bucket " + s3Object.getBucketName() + ")", ace);
                        hasRetried = true;
                    }
                }
            } finally {
                try { s3Object.getObjectContent().abort(); } catch (IOException e) {}
            }
        } while ( needRetry );
        return s3Object;
    }
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

                getObjectRequest.getMatchingETagConstraints());
        addStringListHeader(request, Headers.GET_OBJECT_IF_NONE_MATCH,
                getObjectRequest.getNonmatchingETagConstraints());

        try {
            S3Object s3Object = invoke(request, new S3ObjectResponseHandler(), getObjectRequest.getBucketName(), getObjectRequest.getKey());

            /*
             * 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(getObjectRequest.getBucketName());
            s3Object.setKey(getObjectRequest.getKey());

            /*
             * 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 {
          // Multipart Uploads don't have an MD5 calculated on the service side
          if (isMultipartUploadETag(s3Object.getObjectMetadata().getETag()) == false) {
              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 UnsupportedOperationException();
    }

    @Override
    public PutObjectResult putObject(PutObjectRequest putObjectRequest) throws AmazonClientException, AmazonServiceException {
        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

    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

        throw new UnsupportedOperationException();
    }

    @Override
    public PutObjectResult putObject(PutObjectRequest putObjectRequest) throws AmazonClientException, AmazonServiceException {
        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

        TransferProgressImpl transferProgress = new TransferProgressImpl();
        ProgressListenerChain listenerChain = new ProgressListenerChain(new TransferProgressUpdatingListener(
                transferProgress), getObjectRequest.getProgressListener());
        getObjectRequest.setProgressListener(listenerChain);

        final S3Object s3Object = s3.getObject(getObjectRequest);
        final DownloadImpl download = new DownloadImpl(description, transferProgress, listenerChain, s3Object);

        // null is returned when constraints aren't met
        if (s3Object == null) {
            download.setState(TransferState.Canceled);
            download.setMonitor(new DownloadMonitor(download, null));
            return download;
        }

        long contentLength = s3Object.getObjectMetadata().getContentLength();
        if (getObjectRequest.getRange() != null && getObjectRequest.getRange().length == 2) {
            long startingByte = getObjectRequest.getRange()[0];
            long lastByte     = getObjectRequest.getRange()[1];
            contentLength     = lastByte - startingByte;
        }
View Full Code Here

            @Override
            public Object call() throws Exception {
                try {
                    latch.await();
                    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

                                 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

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.