use of com.google.api.services.storage.model.StorageObject in project google-cloud-java by GoogleCloudPlatform.
the class HttpStorageRpc method list.
@Override
public Tuple<String, Iterable<StorageObject>> list(final String bucket, Map<Option, ?> options) {
try {
Objects objects = storage.objects().list(bucket).setProjection(DEFAULT_PROJECTION).setVersions(Option.VERSIONS.getBoolean(options)).setDelimiter(Option.DELIMITER.getString(options)).setPrefix(Option.PREFIX.getString(options)).setMaxResults(Option.MAX_RESULTS.getLong(options)).setPageToken(Option.PAGE_TOKEN.getString(options)).setFields(Option.FIELDS.getString(options)).execute();
Iterable<StorageObject> storageObjects = Iterables.concat(firstNonNull(objects.getItems(), ImmutableList.<StorageObject>of()), objects.getPrefixes() != null ? Lists.transform(objects.getPrefixes(), objectFromPrefix(bucket)) : ImmutableList.<StorageObject>of());
return Tuple.of(objects.getNextPageToken(), storageObjects);
} catch (IOException ex) {
throw translate(ex);
}
}
use of com.google.api.services.storage.model.StorageObject in project google-cloud-java by GoogleCloudPlatform.
the class StorageImpl method get.
@Override
public Blob get(BlobId blob, BlobGetOption... options) {
final StorageObject storedObject = blob.toPb();
final Map<StorageRpc.Option, ?> optionsMap = optionMap(blob, options);
try {
StorageObject storageObject = runWithRetries(new Callable<StorageObject>() {
@Override
public StorageObject call() {
return storageRpc.get(storedObject, optionsMap);
}
}, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock());
return storageObject == null ? null : Blob.fromPb(this, storageObject);
} catch (RetryHelperException e) {
throw StorageException.translateAndThrow(e);
}
}
use of com.google.api.services.storage.model.StorageObject in project google-cloud-java by GoogleCloudPlatform.
the class StorageImpl method create.
private Blob create(BlobInfo info, final InputStream content, BlobTargetOption... options) {
final StorageObject blobPb = info.toPb();
final Map<StorageRpc.Option, ?> optionsMap = optionMap(info, options);
try {
return Blob.fromPb(this, runWithRetries(new Callable<StorageObject>() {
@Override
public StorageObject call() {
return storageRpc.create(blobPb, firstNonNull(content, new ByteArrayInputStream(EMPTY_BYTE_ARRAY)), optionsMap);
}
}, getOptions().getRetrySettings(), EXCEPTION_HANDLER, getOptions().getClock()));
} catch (RetryHelperException e) {
throw StorageException.translateAndThrow(e);
}
}
use of com.google.api.services.storage.model.StorageObject in project google-cloud-java by GoogleCloudPlatform.
the class StorageImpl method delete.
@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);
}
}
use of com.google.api.services.storage.model.StorageObject in project google-cloud-java by GoogleCloudPlatform.
the class StorageImpl method readAllBytes.
@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);
}
}
Aggregations