Swift TempAuth and Copy commands along with an example by rbramley · Pull Request #64 · woorea/openstack-java-sdk · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions swift-client/src/main/java/org/openstack/swift/api/CopyObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package org.openstack.swift.api;

import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation;
import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.Response;

import org.openstack.swift.SwiftCommand;

/**
* Copy an object.
* "do a PUT to the new object (the target) location, but add the 'X-Copy-From' header to designate the source of the data"
*
* @author Robin Bramley
*/
public class CopyObject implements SwiftCommand<Response>{

private static final String DELIMITER = "/";

private static final String REQ_HEADER_COPY_FROM = "X-Copy-From";

private String sourceContainerName;

private String sourceObjectName;

private String destContainerName;

private String destObjectName;

private String mimeType;

public CopyObject(String sourceContainerName, String sourceObjectName, String destContainerName, String destObjectName, String mimeType) {
this.sourceContainerName = sourceContainerName;
this.sourceObjectName = sourceObjectName;
this.destContainerName = destContainerName;
this.destObjectName = destObjectName;
this.mimeType = mimeType;
}

@Override
public Response execute(WebTarget target) {
// set up the value for the X-Copy-From header
StringBuilder sb = new StringBuilder(2
+ sourceContainerName.length()
+ sourceObjectName.length())
.append(DELIMITER).append(sourceContainerName)
.append(DELIMITER).append(sourceObjectName);
String source = sb.toString();

Invocation.Builder invocationBuilder = target.path(destContainerName).path(destObjectName).request();

invocationBuilder.header(REQ_HEADER_COPY_FROM, source);

return invocationBuilder.put(Entity.entity("", mimeType));
}

}