Search in sources :

Example 11 with Storage

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);
    }
}
Also used : Storage(com.google.cloud.storage.Storage) Test(org.junit.Test)

Example 12 with Storage

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);
}
Also used : Storage(com.google.cloud.storage.Storage) StorageOptions(com.google.cloud.storage.StorageOptions) Before(org.junit.Before)

Example 13 with Storage

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();
    }
}
Also used : Blob(com.google.cloud.storage.Blob) Storage(com.google.cloud.storage.Storage) WritableByteChannel(java.nio.channels.WritableByteChannel) BlobId(com.google.cloud.storage.BlobId)

Example 14 with Storage

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));
}
Also used : Blob(com.google.cloud.storage.Blob) Storage(com.google.cloud.storage.Storage) BlobInfo(com.google.cloud.storage.BlobInfo) BlobId(com.google.cloud.storage.BlobId)

Aggregations

Storage (com.google.cloud.storage.Storage)14 Test (org.junit.Test)6 Blob (com.google.cloud.storage.Blob)4 Policy (com.google.cloud.Policy)3 BlobId (com.google.cloud.storage.BlobId)3 BlobInfo (com.google.cloud.storage.BlobInfo)2 StorageOptions (com.google.cloud.storage.StorageOptions)2 Role (com.google.cloud.Role)1 Bucket (com.google.cloud.storage.Bucket)1 CopyWriter (com.google.cloud.storage.CopyWriter)1 IOException (java.io.IOException)1 WritableByteChannel (java.nio.channels.WritableByteChannel)1 KeyStoreException (java.security.KeyStoreException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 UnrecoverableKeyException (java.security.UnrecoverableKeyException)1 CertificateException (java.security.cert.CertificateException)1 Map (java.util.Map)1 Set (java.util.Set)1 Before (org.junit.Before)1