Search in sources :

Example 81 with Object

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

the class SyncGetObjectStringString method syncGetObjectStringString.

public static void syncGetObjectStringString() throws Exception {
    // It may require modifications to work in your environment.
    try (StorageClient storageClient = StorageClient.create()) {
        String bucket = "bucket-1378203158";
        String object = "object-1023368385";
        Object response = storageClient.getObject(bucket, object);
    }
}
Also used : StorageClient(com.google.storage.v2.StorageClient) Object(com.google.storage.v2.Object)

Example 82 with Object

use of com.google.storage.v2.Object in project grpc-gcp-java by GoogleCloudPlatform.

the class GrpcClient method makeReadObjectRequest.

private void makeReadObjectRequest(ManagedChannel channel, ResultTable results, int threadId) {
    StorageGrpc.StorageBlockingStub blockingStub = StorageGrpc.newBlockingStub(channel);
    if (creds != null) {
        blockingStub = blockingStub.withCallCredentials(MoreCallCredentials.from(creds));
    }
    byte[] scratch = new byte[4 * 1024 * 1024];
    for (int i = 0; i < args.calls; i++) {
        String object = objectResolver.Resolve(threadId, i);
        ReadObjectRequest readRequest = ReadObjectRequest.newBuilder().setBucket(toV2BucketName(args.bkt)).setObject(object).build();
        long start = System.currentTimeMillis();
        long totalBytes = 0;
        Iterator<ReadObjectResponse> resIterator;
        if (useZeroCopy) {
            resIterator = io.grpc.stub.ClientCalls.blockingServerStreamingCall(blockingStub.getChannel(), readObjectMethod, blockingStub.getCallOptions(), readRequest);
        } else {
            resIterator = blockingStub.readObject(readRequest);
        }
        try {
            while (true) {
                ReadObjectResponse res = resIterator.next();
                // When zero-copy mashaller is used, the stream that backs ReadObjectResponse
                // should be closed when the mssage is no longed needed so that all buffers in the
                // stream can be reclaimed. If zero-copy is not used, stream will be null.
                InputStream stream = ReadObjectResponseMarshaller.popStream(res);
                try {
                    // Just copy to scratch memory to ensure its data is consumed.
                    ByteString content = res.getChecksummedData().getContent();
                    totalBytes += content.size();
                    content.copyTo(scratch, 0);
                } finally {
                    if (stream != null) {
                        try {
                            stream.close();
                        } catch (IOException e) {
                            throw new RuntimeException(e);
                        }
                    }
                }
            }
        } catch (NoSuchElementException e) {
        }
        long dur = System.currentTimeMillis() - start;
        results.reportResult(args.bkt, object, totalBytes, dur);
    }
}
Also used : ReadObjectResponse(com.google.storage.v2.ReadObjectResponse) ReadObjectRequest(com.google.storage.v2.ReadObjectRequest) InputStream(java.io.InputStream) ByteString(com.google.protobuf.ByteString) StorageGrpc(com.google.storage.v2.StorageGrpc) ByteString(com.google.protobuf.ByteString) IOException(java.io.IOException) StorageBlockingStub(com.google.storage.v2.StorageGrpc.StorageBlockingStub) NoSuchElementException(java.util.NoSuchElementException)

Aggregations

Object (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.Object)33 ArrayList (java.util.ArrayList)25 Object (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.Object)18 StorageClient (com.google.storage.v2.StorageClient)16 Object (com.google.storage.v2.Object)12 Test (org.junit.Test)12 PCEPDeserializerException (org.opendaylight.protocol.pcep.spi.PCEPDeserializerException)12 VendorInformationObject (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.vendor.information.objects.VendorInformationObject)12 Object (no.mnemonic.act.platform.api.model.v1.Object)8 Preconditions (com.google.common.base.Preconditions)6 ObjectRecord (no.mnemonic.act.platform.dao.api.record.ObjectRecord)6 Metrics (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.lsp.attributes.Metrics)6 Metrics (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev131005.lsp.attributes.Metrics)5 Ero (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.types.rev181109.explicit.route.object.Ero)5 AbstractMessage (com.google.protobuf.AbstractMessage)4 ByteString (com.google.protobuf.ByteString)4 PCEPErrors (org.opendaylight.protocol.pcep.spi.PCEPErrors)4 UnknownObject (org.opendaylight.protocol.pcep.spi.UnknownObject)4 Lsp (org.opendaylight.yang.gen.v1.urn.opendaylight.params.xml.ns.yang.pcep.ietf.stateful.rev200720.lsp.object.Lsp)4 ListObjectsPagedResponse (com.google.storage.v2.StorageClient.ListObjectsPagedResponse)3