use of com.google.api.services.storage.model.StorageObject in project google-cloud-java by GoogleCloudPlatform.
the class FakeStorageRpc method get.
/**
* Returns the requested storage object or {@code null} if not found.
*/
@Override
public StorageObject get(StorageObject object, Map<Option, ?> options) throws StorageException {
// because the caller won't mind the extra fields.
if (throwIfOption && !options.isEmpty() && options.size() > 1 && options.keySet().toArray()[0] != Storage.BlobGetOption.fields(Storage.BlobField.ID)) {
throw new UnsupportedOperationException();
}
String key = fullname(object);
if (metadata.containsKey(key)) {
StorageObject ret = metadata.get(key);
if (contents.containsKey(key)) {
ret.setSize(BigInteger.valueOf(contents.get(key).length));
}
ret.setId(key);
return ret;
}
return null;
}
use of com.google.api.services.storage.model.StorageObject in project google-cloud-java by GoogleCloudPlatform.
the class StorageBatchTest method testGetWithOptions.
@Test
public void testGetWithOptions() {
EasyMock.reset(storage, batchMock, optionsMock);
EasyMock.expect(storage.getOptions()).andReturn(optionsMock).times(2);
EasyMock.expect(optionsMock.getService()).andReturn(storage);
Capture<RpcBatch.Callback<StorageObject>> callback = Capture.newInstance();
Capture<Map<StorageRpc.Option, Object>> capturedOptions = Capture.newInstance();
batchMock.addGet(EasyMock.eq(BLOB_INFO.toPb()), EasyMock.capture(callback), EasyMock.capture(capturedOptions));
EasyMock.replay(storage, batchMock, optionsMock);
StorageBatchResult<Blob> batchResult = storageBatch.get(BLOB_ID, BLOB_GET_OPTIONS);
assertNotNull(callback.getValue());
assertEquals(2, capturedOptions.getValue().size());
for (BlobGetOption option : BLOB_GET_OPTIONS) {
assertEquals(option.getValue(), capturedOptions.getValue().get(option.getRpcOption()));
}
RpcBatch.Callback<StorageObject> capturedCallback = callback.getValue();
capturedCallback.onSuccess(BLOB_INFO.toPb());
assertEquals(new Blob(storage, new Blob.BuilderImpl(BLOB_INFO)), batchResult.get());
}
use of com.google.api.services.storage.model.StorageObject in project gradle by gradle.
the class GcsClient method list.
@Nullable
public List<String> list(URI uri) throws ResourceException {
List<StorageObject> results = new ArrayList<StorageObject>();
String path = cleanResourcePath(uri);
try {
Storage.Objects.List listRequest = storage.objects().list(uri.getHost()).setPrefix(path);
Objects objects;
// Iterate through each page of results, and add them to our results list.
do {
objects = listRequest.execute();
// Add the items in this page of results to the list we'll return.
results.addAll(objects.getItems());
// Get the next page, in the next iteration of this loop.
listRequest.setPageToken(objects.getNextPageToken());
} while (null != objects.getNextPageToken());
} catch (IOException e) {
throw ResourceExceptions.getFailed(uri, e);
}
List<String> resultStrings = new ArrayList<String>();
for (StorageObject result : results) {
resultStrings.add(result.getName());
}
return resultStrings;
}
use of com.google.api.services.storage.model.StorageObject in project gradle by gradle.
the class GcsResourceConnector method openResource.
@Nullable
@Override
public ExternalResourceReadResponse openResource(URI location, boolean revalidate) throws ResourceException {
LOGGER.debug("Attempting to get resource: {}", location);
StorageObject gcsObject = gcsClient.getResource(location);
if (gcsObject == null) {
return null;
}
return new GcsResource(gcsClient, gcsObject, location);
}
use of com.google.api.services.storage.model.StorageObject in project ignite by apache.
the class TcpDiscoveryGoogleStorageIpFinder method registerAddresses.
/**
* {@inheritDoc}
*/
@Override
public void registerAddresses(Collection<InetSocketAddress> addrs) throws IgniteSpiException {
assert !F.isEmpty(addrs);
init();
for (InetSocketAddress addr : addrs) {
String key = keyFromAddr(addr);
StorageObject object = new StorageObject();
object.setBucket(bucketName);
object.setName(key);
InputStreamContent content = new InputStreamContent("application/octet-stream", OBJECT_CONTENT);
content.setLength(OBJECT_CONTENT.available());
try {
Storage.Objects.Insert insertObject = storage.objects().insert(bucketName, object, content);
insertObject.execute();
} catch (Exception e) {
throw new IgniteSpiException("Failed to put entry [bucketName=" + bucketName + ", entry=" + key + ']', e);
}
}
}
Aggregations