Logo Search packages:      
Sourcecode: jets3t version File versions  Download package

Map org::jets3t::service::impl::rest::httpclient::RestS3Service::copyObjectImpl ( String  sourceBucketName,
String  sourceObjectKey,
String  destinationBucketName,
String  destinationObjectKey,
AccessControlList  acl,
Map  destinationMetadata,
Calendar  ifModifiedSince,
Calendar  ifUnmodifiedSince,
String[]  ifMatchTags,
String[]  ifNoneMatchTags,
String  versionId 
) throws S3ServiceException [inline, protected, virtual]

Copy an object within your S3 account. Copies within a single bucket or between buckets, and optionally updates the object's metadata at the same time. An object can be copied over itself, allowing you to update the metadata without making any other changes.

sourceBucketName the name of the bucket that contains the original object.
sourceObjectKey the key name of the original object.
destinationBucketName the name of the destination bucket to which the object will be copied.
destinationObjectKey the key name for the copied object.
acl the access control settings that will be applied to the copied object. If this parameter is null, the default (private) ACL setting will be applied to the copied object.
destinationMetadata metadata items to apply to the copied object. If this parameter is null, the metadata will be copied unchanged from the original object. If this parameter is not null, the copied object will have only the supplied metadata.
a map of the header and result information returned by S3 after the object copy. The map includes the object's MD5 hash value (ETag), its size (Content-Length), and update timestamp (Last-Modified).

Implements org::jets3t::service::S3Service.

Definition at line 1776 of file RestS3Service.java.

References convertHeadersToMap(), org::jets3t::service::impl::rest::httpclient::RestS3Service::HttpMethodAndByteCount::getHttpMethod(), and performRestPut().

        if (log.isDebugEnabled()) {
            log.debug("Copying Object from " + sourceBucketName + ":" + sourceObjectKey
                + " to " + destinationBucketName + ":" + destinationObjectKey);

        Map metadata = new HashMap();

        String sourceKey = RestUtils.encodeUrlString(sourceBucketName + "/" + sourceObjectKey);
        if (versionId != null) {
            sourceKey += "?versionId=" + versionId;

        metadata.put("x-amz-copy-source", sourceKey);

        if (destinationMetadata != null) {
            metadata.put("x-amz-metadata-directive", "REPLACE");
            // Include any metadata provided with S3 object.
            // Set default content type.
            if (!metadata.containsKey("Content-Type")) {
                metadata.put("Content-Type", Mimetypes.MIMETYPE_OCTET_STREAM);
        } else {
            metadata.put("x-amz-metadata-directive", "COPY");

        boolean putNonStandardAcl = false;
        if (acl != null) {
            if (AccessControlList.REST_CANNED_PRIVATE.equals(acl)) {
                metadata.put(Constants.REST_HEADER_PREFIX + "acl", "private");
            } else if (AccessControlList.REST_CANNED_PUBLIC_READ.equals(acl)) {
                metadata.put(Constants.REST_HEADER_PREFIX + "acl", "public-read");
            } else if (AccessControlList.REST_CANNED_PUBLIC_READ_WRITE.equals(acl)) {
                metadata.put(Constants.REST_HEADER_PREFIX + "acl", "public-read-write");
            } else if (AccessControlList.REST_CANNED_AUTHENTICATED_READ.equals(acl)) {
                metadata.put(Constants.REST_HEADER_PREFIX + "acl", "authenticated-read");
            } else {
                putNonStandardAcl = true;

        if (ifModifiedSince != null) {
            if (log.isDebugEnabled()) {
                log.debug("Only copy object if-modified-since:" + ifModifiedSince);
        if (ifUnmodifiedSince != null) {
            if (log.isDebugEnabled()) {
                log.debug("Only copy object if-unmodified-since:" + ifUnmodifiedSince);
        if (ifMatchTags != null) {
            String tags = ServiceUtils.join(ifMatchTags, ",");
            metadata.put("x-amz-copy-source-if-match", tags);
            if (log.isDebugEnabled()) {
                log.debug("Only copy object based on hash comparison if-match:" + tags);
        if (ifNoneMatchTags != null) {
            String tags = ServiceUtils.join(ifNoneMatchTags, ",");
            metadata.put("x-amz-copy-source-if-none-match", tags);
            if (log.isDebugEnabled()) {
                log.debug("Only copy object based on hash comparison if-none-match:" + tags);

        HttpMethodAndByteCount methodAndByteCount = performRestPut(
            destinationBucketName, destinationObjectKey, metadata, null, null, false);

        CopyObjectResultHandler handler = (new XmlResponsesSaxParser(this.jets3tProperties))
                new HttpMethodReleaseInputStream(methodAndByteCount.getHttpMethod()));

        // Release HTTP connection manually. This should already have been done by the
        // HttpMethodReleaseInputStream class, but you can never be too sure...

        if (handler.isErrorResponse()) {
            throw new S3ServiceException(
                "Copy failed: Code=" + handler.getErrorCode() +
                ", Message=" + handler.getErrorMessage() +
                ", RequestId=" + handler.getErrorRequestId() +
                ", HostId=" + handler.getErrorHostId());

        Map map = new HashMap();

        // Result fields returned when copy is successful.
        map.put("Last-Modified", handler.getLastModified());
        map.put("ETag", handler.getETag());

        // Include response headers in result map.
        map = ServiceUtils.cleanRestMetadataMap(map);

        if (putNonStandardAcl) {
            if (log.isDebugEnabled()) {
                log.debug("Creating object with a non-canned ACL using REST, so an extra ACL Put is required");
            putAclImpl(destinationBucketName, destinationObjectKey, acl, null);

        return map;

Generated by  Doxygen 1.6.0   Back to index