use of com.google.cloud.storage.Storage in project google-cloud-java by GoogleCloudPlatform.
the class RemoteStorageHelperTest method testForceDeleteNoTimeoutFail.
@Test
public void testForceDeleteNoTimeoutFail() {
Storage storageMock = EasyMock.createMock(Storage.class);
EasyMock.expect(blob1.getBlobId()).andReturn(BLOB_ID1);
EasyMock.expect(storageMock.delete(BLOB_ID1)).andReturn(true);
EasyMock.expect(blob2.getBlobId()).andReturn(BLOB_ID2);
EasyMock.expect(storageMock.delete(BLOB_ID2)).andReturn(true);
EasyMock.expect(storageMock.list(BUCKET_NAME, BlobListOption.versions(true))).andReturn(blobPage);
EasyMock.expect(storageMock.delete(BUCKET_NAME)).andThrow(FATAL_EXCEPTION);
EasyMock.replay(storageMock, blob1, blob2);
thrown.expect(StorageException.class);
try {
RemoteStorageHelper.forceDelete(storageMock, BUCKET_NAME);
} finally {
EasyMock.verify(storageMock);
}
}
use of com.google.cloud.storage.Storage in project google-cloud-java by GoogleCloudPlatform.
the class CloudStorageLateInitializationTest method before.
@Before
public void before() {
mockOptions = mock(StorageOptions.class);
Storage mockStorage = mock(Storage.class);
when(mockOptions.getService()).thenReturn(mockStorage);
CloudStorageFileSystemProvider.setStorageOptions(mockOptions);
}
use of com.google.cloud.storage.Storage in project google-cloud-java by GoogleCloudPlatform.
the class UpdateBlob method main.
public static void main(String... args) throws IOException {
Storage storage = StorageOptions.getDefaultInstance().getService();
BlobId blobId = BlobId.of("bucket", "blob_name");
Blob blob = storage.get(blobId);
if (blob != null) {
byte[] prevContent = blob.getContent();
System.out.println(new String(prevContent, UTF_8));
WritableByteChannel channel = blob.writer();
channel.write(ByteBuffer.wrap("Updated content".getBytes(UTF_8)));
channel.close();
}
}
use of com.google.cloud.storage.Storage in project google-cloud-java by GoogleCloudPlatform.
the class CreateBlob method main.
public static void main(String... args) {
Storage storage = StorageOptions.getDefaultInstance().getService();
BlobId blobId = BlobId.of("bucket", "blob_name");
BlobInfo blobInfo = BlobInfo.newBuilder(blobId).setContentType("text/plain").build();
Blob blob = storage.create(blobInfo, "Hello, Cloud Storage!".getBytes(UTF_8));
}
Aggregations