Package com.amazonaws.services.s3.model

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


        @Override
        public S3Object getObject(String bucketName, String key) throws AmazonClientException, AmazonServiceException {
            assertEquals("mycamelbucket", bucketName);
            assertEquals("key", key);
           
            S3Object s3Object = new S3Object();
            s3Object.setBucketName(bucketName);
            s3Object.setKey(key);
            try {
                s3Object.setObjectContent(new StringInputStream("Camel rocks!"));
            } catch (UnsupportedEncodingException e) {
                // noop
            }
           
            return s3Object;
View Full Code Here


    public InputStream read(DataIdentifier identifier)
            throws DataStoreException {
        String key = getKeyName(identifier);
        try {
            LOG.debug("read {" + identifier + "}");
            S3Object object = s3service.getObject(bucket, key);
            InputStream in = object.getObjectContent();
            LOG.debug("  return");
            return in;
        } catch (AmazonServiceException e) {
            throw new DataStoreException("Object not found: " + key, e);
        }
View Full Code Here

                                 throw new AmazonClientException("Couldn't wait for setting future into the monitor");
                             }
                     }
                   }
                    download.setState(TransferState.InProgress);
                    final S3Object s3Object = s3.getObject(getObjectRequest);
                   
                    download.setS3Object(s3Object);
 
                     if (s3Object == null) {
                        download.setState(TransferState.Canceled);
View Full Code Here

        if (adjustedCryptoRange != null) {
            getObjectRequest.setRange(adjustedCryptoRange[0], adjustedCryptoRange[1]);
        }

        // Get the object from S3
        S3Object retrievedObject = super.getObject(getObjectRequest);

        // If the caller has specified constraints, it's possible that super.getObject(...)
        // would return null, so we simply return null as well.
        if (retrievedObject == null) return null;

        S3Object objectToBeReturned;
        // Check if encryption info is in object metadata
        if (EncryptionUtils.isEncryptionInfoInMetadata(retrievedObject)) {
            objectToBeReturned = decryptObjectUsingMetadata(retrievedObject);
        } else {
            // Check if encrypted info is in an instruction file
            S3Object instructionFile = getInstructionFile(getObjectRequest);
            if (EncryptionUtils.isEncryptionInfoInInstructionFile(instructionFile)) {
                objectToBeReturned = decryptObjectUsingInstructionFile(retrievedObject, instructionFile);
            } else {
                // The object was not encrypted to begin with.  Return the object without decrypting it.
                log.warn(String.format("Unable to detect encryption information for object '%s' in bucket '%s'. " +
View Full Code Here

    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) {}
        }

        /*
         * Unlike the standard Amazon S3 Client, the Amazon S3 Encryption Client does not do an MD5 check
         * here because the contents stored in S3 and the contents we just retrieved are different.  In
         * S3, the stored contents are encrypted, and locally, the retrieved contents are decrypted.
         */

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

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

        ProgressListener progressListener = getObjectRequest.getProgressListener();
        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());

            if (progressListener != null) {
                S3ObjectInputStream input = s3Object.getObjectContent();
                ProgressReportingInputStream progressReportingInputStream = new ProgressReportingInputStream(input, progressListener);
                progressReportingInputStream.setFireCompletedEvent(true);
                input = new S3ObjectInputStream(progressReportingInputStream, input.getHttpRequest());
                s3Object.setObjectContent(input);
                fireProgressEvent(progressListener, ProgressEvent.STARTED_EVENT_CODE);
            }

            /*
             * TODO: It'd be nice to check the integrity of the data was received from S3,
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;

        ServiceUtils.downloadObjectToFile(s3Object, destinationFile,(getObjectRequest.getRange()==null));

        return s3Object.getObjectMetadata();
    }
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();
        AmazonWebServiceResponse<S3Object> awsResponse = parseResponseMetadata(response);
        if (response.getHeaders().get(Headers.REDIRECT_LOCATION) != null) {
            object.setRedirectLocation(response.getHeaders().get(Headers.REDIRECT_LOCATION));
        }
        ObjectMetadata metadata = object.getObjectMetadata();
        populateObjectMetadata(response, metadata);
        boolean hasServerSideCalculatedChecksum = !ServiceUtils.isMultipartUploadETag(metadata.getETag());
        boolean responseContainsEntireObject = response.getHeaders().get("Content-Range") == null;

        if (hasServerSideCalculatedChecksum && responseContainsEntireObject) {
            byte[] expectedChecksum = BinaryUtils.fromHex(metadata.getETag());
            object.setObjectContent(new S3ObjectInputStream(new ChecksumValidatingInputStream(response.getContent(), expectedChecksum, object.getBucketName() + "/" + object.getKey()), response
                    .getHttpRequest()));
        } else {
            object.setObjectContent(new S3ObjectInputStream(response.getContent(), response.getHttpRequest()));
        }

        awsResponse.setResult(object);
        return awsResponse;
    }
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());
       
        ResponseMetadata<S3Object> responseMetadata = parseResponseMetadata(response);
        responseMetadata.setResult(object);
       
        return responseMetadata;
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

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.