@Override public StorageBatch batch() { return new StorageBatch(this.getOptions()); }
@Override public ReadChannel reader(BlobId blob, BlobSourceOption... options) { Map<StorageRpc.Option, ?> optionsMap = optionMap(blob, options); return new BlobReadChannel(getOptions(), blob, optionsMap); }
@Override public Page<Bucket> list(BucketListOption... options) { return listBuckets(getOptions(), optionMap(options)); }
private BlobWriteChannel writer(BlobInfo blobInfo, BlobTargetOption... options) { final Map<StorageRpc.Option, ?> optionsMap = optionMap(blobInfo, options); return new BlobWriteChannel(getOptions(), blobInfo, optionsMap); }
@Override public Page<Blob> list(final String bucket, BlobListOption... options) { return listBlobs(bucket, getOptions(), optionMap(options)); }
@Override public boolean deleteAcl( final String bucket, final Entity entity, BucketSourceOption... options) { try { final Map<StorageRpc.Option, ?> optionsMap = optionMap(options); return runWithRetries( new Callable<Boolean>() { @Override public Boolean call() { return storageRpc.deleteAcl(bucket, entity.toPb(), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public Acl getAcl(final String bucket, final Entity entity, BucketSourceOption... options) { try { final Map<StorageRpc.Option, ?> optionsMap = optionMap(options); BucketAccessControl answer = runWithRetries( new Callable<BucketAccessControl>() { @Override public BucketAccessControl call() { return storageRpc.getAcl(bucket, entity.toPb(), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Acl.fromPb(answer); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public Policy setIamPolicy( final String bucket, final Policy policy, BucketSourceOption... options) { try { final Map<StorageRpc.Option, ?> optionsMap = optionMap(options); return convertFromApiPolicy( runWithRetries( new Callable<com.google.api.services.storage.model.Policy>() { @Override public com.google.api.services.storage.model.Policy call() { return storageRpc.setIamPolicy(bucket, convertToApiPolicy(policy), optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock())); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public Policy getIamPolicy(final String bucket, BucketSourceOption... options) { try { final Map<StorageRpc.Option, ?> optionsMap = optionMap(options); return convertFromApiPolicy( runWithRetries( new Callable<com.google.api.services.storage.model.Policy>() { @Override public com.google.api.services.storage.model.Policy call() { return storageRpc.getIamPolicy(bucket, optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock())); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public ReadChannel reader(String bucket, String blob, BlobSourceOption... options) { Map<StorageRpc.Option, ?> optionsMap = optionMap(options); return new BlobReadChannel(getOptions(), BlobId.of(bucket, blob), optionsMap); }
@Override public boolean deleteDefaultAcl(final String bucket, final Entity entity) { try { return runWithRetries( new Callable<Boolean>() { @Override public Boolean call() { return storageRpc.deleteDefaultAcl(bucket, entity.toPb()); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public boolean deleteAcl(final BlobId blob, final Entity entity) { try { return runWithRetries( new Callable<Boolean>() { @Override public Boolean call() { return storageRpc.deleteAcl( blob.getBucket(), blob.getName(), blob.getGeneration(), entity.toPb()); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public boolean delete(BlobId blob, BlobSourceOption... options) { final StorageObject storageObject = blob.toPb(); final Map<StorageRpc.Option, ?> optionsMap = optionMap(blob, options); try { return runWithRetries( new Callable<Boolean>() { @Override public Boolean call() { return storageRpc.delete(storageObject, optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public byte[] readAllBytes(BlobId blob, BlobSourceOption... options) { final StorageObject storageObject = blob.toPb(); final Map<StorageRpc.Option, ?> optionsMap = optionMap(blob, options); try { return runWithRetries( new Callable<byte[]>() { @Override public byte[] call() { return storageRpc.load(storageObject, optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public Acl getDefaultAcl(final String bucket, final Entity entity) { try { ObjectAccessControl answer = runWithRetries( new Callable<ObjectAccessControl>() { @Override public ObjectAccessControl call() { return storageRpc.getDefaultAcl(bucket, entity.toPb()); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Acl.fromPb(answer); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public Acl getAcl(final BlobId blob, final Entity entity) { try { ObjectAccessControl answer = runWithRetries( new Callable<ObjectAccessControl>() { @Override public ObjectAccessControl call() { return storageRpc.getAcl( blob.getBucket(), blob.getName(), blob.getGeneration(), entity.toPb()); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : Acl.fromPb(answer); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public ServiceAccount getServiceAccount(final String projectId) { try { com.google.api.services.storage.model.ServiceAccount answer = runWithRetries( new Callable<com.google.api.services.storage.model.ServiceAccount>() { @Override public com.google.api.services.storage.model.ServiceAccount call() { return storageRpc.getServiceAccount(projectId); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return answer == null ? null : ServiceAccount.fromPb(answer); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public boolean delete(String bucket, BucketSourceOption... options) { final com.google.api.services.storage.model.Bucket bucketPb = BucketInfo.of(bucket).toPb(); final Map<StorageRpc.Option, ?> optionsMap = optionMap(options); try { return runWithRetries( new Callable<Boolean>() { @Override public Boolean call() { return storageRpc.delete(bucketPb, optionsMap); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public List<Acl> listAcls(final BlobId blob) { try { List<ObjectAccessControl> answer = runWithRetries( new Callable<List<ObjectAccessControl>>() { @Override public List<ObjectAccessControl> call() { return storageRpc.listAcls( blob.getBucket(), blob.getName(), blob.getGeneration()); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()); return Lists.transform(answer, Acl.FROM_OBJECT_PB_FUNCTION); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }
@Override public Acl createDefaultAcl(String bucket, Acl acl) { final ObjectAccessControl aclPb = acl.toObjectPb().setBucket(bucket); try { return Acl.fromPb( runWithRetries( new Callable<ObjectAccessControl>() { @Override public ObjectAccessControl call() { return storageRpc.createDefaultAcl(aclPb); } }, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock())); } catch (RetryHelperException e) { throw StorageException.translateAndThrow(e); } }