Search in sources :

Example 6 with StorageClient

use of com.google.storage.v2.StorageClient in project gapic-generator-java by googleapis.

the class AsyncWriteObject method asyncWriteObject.

public static void asyncWriteObject() throws Exception {
    // It may require modifications to work in your environment.
    try (StorageClient storageClient = StorageClient.create()) {
        ApiStreamObserver<WriteObjectRequest> responseObserver = new ApiStreamObserver<WriteObjectRequest>() {

            @Override
            public void onNext(WriteObjectResponse response) {
            // Do something when a response is received.
            }

            @Override
            public void onError(Throwable t) {
            // Add error-handling
            }

            @Override
            public void onCompleted() {
            // Do something when complete.
            }
        };
        ApiStreamObserver<WriteObjectRequest> requestObserver = storageClient.writeObject().clientStreamingCall(responseObserver);
        WriteObjectRequest request = WriteObjectRequest.newBuilder().setWriteOffset(-1559543565).setObjectChecksums(ObjectChecksums.newBuilder().build()).setFinishWrite(true).setCommonObjectRequestParams(CommonObjectRequestParams.newBuilder().build()).setCommonRequestParams(CommonRequestParams.newBuilder().build()).build();
        requestObserver.onNext(request);
    }
}
Also used : ApiStreamObserver(com.google.api.gax.rpc.ApiStreamObserver) StorageClient(com.google.storage.v2.StorageClient) WriteObjectRequest(com.google.storage.v2.WriteObjectRequest) WriteObjectResponse(com.google.storage.v2.WriteObjectResponse)

Example 7 with StorageClient

use of com.google.storage.v2.StorageClient in project gapic-generator-java by googleapis.

the class AsyncQueryWriteStatus method asyncQueryWriteStatus.

public static void asyncQueryWriteStatus() throws Exception {
    // It may require modifications to work in your environment.
    try (StorageClient storageClient = StorageClient.create()) {
        QueryWriteStatusRequest request = QueryWriteStatusRequest.newBuilder().setUploadId("uploadId1563990780").setCommonObjectRequestParams(CommonObjectRequestParams.newBuilder().build()).setCommonRequestParams(CommonRequestParams.newBuilder().build()).build();
        ApiFuture<QueryWriteStatusResponse> future = storageClient.queryWriteStatusCallable().futureCall(request);
        // Do something.
        QueryWriteStatusResponse response = future.get();
    }
}
Also used : QueryWriteStatusResponse(com.google.storage.v2.QueryWriteStatusResponse) StorageClient(com.google.storage.v2.StorageClient) QueryWriteStatusRequest(com.google.storage.v2.QueryWriteStatusRequest)

Example 8 with StorageClient

use of com.google.storage.v2.StorageClient in project gapic-generator-java by googleapis.

the class AsyncReadObject method asyncReadObject.

public static void asyncReadObject() throws Exception {
    // It may require modifications to work in your environment.
    try (StorageClient storageClient = StorageClient.create()) {
        ReadObjectRequest request = ReadObjectRequest.newBuilder().setBucket("bucket-1378203158").setObject("object-1023368385").setGeneration(305703192).setReadOffset(-715377828).setReadLimit(-164298798).setIfGenerationMatch(-1086241088).setIfGenerationNotMatch(1475720404).setIfMetagenerationMatch(1043427781).setIfMetagenerationNotMatch(1025430873).setCommonObjectRequestParams(CommonObjectRequestParams.newBuilder().build()).setCommonRequestParams(CommonRequestParams.newBuilder().build()).setReadMask(FieldMask.newBuilder().build()).build();
        ServerStream<ReadObjectResponse> stream = storageClient.readObjectCallable().call(request);
        for (ReadObjectResponse response : stream) {
        // Do something when a response is received.
        }
    }
}
Also used : ReadObjectResponse(com.google.storage.v2.ReadObjectResponse) ReadObjectRequest(com.google.storage.v2.ReadObjectRequest) StorageClient(com.google.storage.v2.StorageClient)

Example 9 with StorageClient

use of com.google.storage.v2.StorageClient in project gapic-generator-java by googleapis.

the class SyncRewriteObject method syncRewriteObject.

public static void syncRewriteObject() throws Exception {
    // It may require modifications to work in your environment.
    try (StorageClient storageClient = StorageClient.create()) {
        RewriteObjectRequest request = RewriteObjectRequest.newBuilder().setDestinationName("destinationName-1762755655").setDestinationBucket(BucketName.of("[PROJECT]", "[BUCKET]").toString()).setDestinationKmsKey(CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]").toString()).setDestination(Object.newBuilder().build()).setSourceBucket("sourceBucket841604581").setSourceObject("sourceObject1196439354").setSourceGeneration(1232209852).setRewriteToken("rewriteToken80654285").setDestinationPredefinedAcl(PredefinedObjectAcl.forNumber(0)).setIfGenerationMatch(-1086241088).setIfGenerationNotMatch(1475720404).setIfMetagenerationMatch(1043427781).setIfMetagenerationNotMatch(1025430873).setIfSourceGenerationMatch(-1427877280).setIfSourceGenerationNotMatch(1575612532).setIfSourceMetagenerationMatch(1143319909).setIfSourceMetagenerationNotMatch(1900822777).setMaxBytesRewrittenPerCall(1178170730).setCopySourceEncryptionAlgorithm("copySourceEncryptionAlgorithm-1524952548").setCopySourceEncryptionKeyBytes(ByteString.EMPTY).setCopySourceEncryptionKeySha256Bytes(ByteString.EMPTY).setCommonObjectRequestParams(CommonObjectRequestParams.newBuilder().build()).setCommonRequestParams(CommonRequestParams.newBuilder().build()).build();
        RewriteResponse response = storageClient.rewriteObject(request);
    }
}
Also used : RewriteObjectRequest(com.google.storage.v2.RewriteObjectRequest) StorageClient(com.google.storage.v2.StorageClient) RewriteResponse(com.google.storage.v2.RewriteResponse)

Example 10 with StorageClient

use of com.google.storage.v2.StorageClient in project gapic-generator-java by googleapis.

the class SyncSetIamPolicy method syncSetIamPolicy.

public static void syncSetIamPolicy() throws Exception {
    // It may require modifications to work in your environment.
    try (StorageClient storageClient = StorageClient.create()) {
        SetIamPolicyRequest request = SetIamPolicyRequest.newBuilder().setResource(CryptoKeyName.of("[PROJECT]", "[LOCATION]", "[KEY_RING]", "[CRYPTO_KEY]").toString()).setPolicy(Policy.newBuilder().build()).build();
        Policy response = storageClient.setIamPolicy(request);
    }
}
Also used : Policy(com.google.iam.v1.Policy) SetIamPolicyRequest(com.google.iam.v1.SetIamPolicyRequest) StorageClient(com.google.storage.v2.StorageClient)

Aggregations

StorageClient (com.google.storage.v2.StorageClient)93 Bucket (com.google.storage.v2.Bucket)17 Object (com.google.storage.v2.Object)11 Notification (com.google.storage.v2.Notification)10 HmacKeyMetadata (com.google.storage.v2.HmacKeyMetadata)9 Policy (com.google.iam.v1.Policy)8 ProjectName (com.google.storage.v2.ProjectName)6 ArrayList (java.util.ArrayList)6 TestIamPermissionsResponse (com.google.iam.v1.TestIamPermissionsResponse)4 Empty (com.google.protobuf.Empty)4 BucketName (com.google.storage.v2.BucketName)4 CreateHmacKeyResponse (com.google.storage.v2.CreateHmacKeyResponse)4 ServiceAccount (com.google.storage.v2.ServiceAccount)4 ResourceName (com.google.api.resourcenames.ResourceName)3 FieldMask (com.google.protobuf.FieldMask)3 QueryWriteStatusResponse (com.google.storage.v2.QueryWriteStatusResponse)3 GetIamPolicyRequest (com.google.iam.v1.GetIamPolicyRequest)2 SetIamPolicyRequest (com.google.iam.v1.SetIamPolicyRequest)2 TestIamPermissionsRequest (com.google.iam.v1.TestIamPermissionsRequest)2 ComposeObjectRequest (com.google.storage.v2.ComposeObjectRequest)2