Search in sources :

Example 1 with RewriteResponse

use of com.google.cloud.storage.spi.v1.StorageRpc.RewriteResponse in project google-cloud-java by GoogleCloudPlatform.

the class StorageImpl method copy.

@Override
public CopyWriter copy(final CopyRequest copyRequest) {
    final StorageObject source = copyRequest.getSource().toPb();
    final Map<StorageRpc.Option, ?> sourceOptions = optionMap(copyRequest.getSource().getGeneration(), null, copyRequest.getSourceOptions(), true);
    final StorageObject targetObject = copyRequest.getTarget().toPb();
    final Map<StorageRpc.Option, ?> targetOptions = optionMap(copyRequest.getTarget().getGeneration(), copyRequest.getTarget().getMetageneration(), copyRequest.getTargetOptions());
    try {
        RewriteResponse rewriteResponse = runWithRetries(new Callable<RewriteResponse>() {

            @Override
            public RewriteResponse call() {
                return storageRpc.openRewrite(new StorageRpc.RewriteRequest(source, sourceOptions, copyRequest.overrideInfo(), targetObject, targetOptions, copyRequest.getMegabytesCopiedPerChunk()));
            }
        }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock());
        return new CopyWriter(getOptions(), rewriteResponse);
    } catch (RetryHelperException e) {
        throw StorageException.translateAndThrow(e);
    }
}
Also used : StorageObject(com.google.api.services.storage.model.StorageObject) RewriteResponse(com.google.cloud.storage.spi.v1.StorageRpc.RewriteResponse) RetryHelperException(com.google.cloud.RetryHelper.RetryHelperException)

Aggregations

StorageObject (com.google.api.services.storage.model.StorageObject)1 RetryHelperException (com.google.cloud.RetryHelper.RetryHelperException)1 RewriteResponse (com.google.cloud.storage.spi.v1.StorageRpc.RewriteResponse)1