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);
}
}
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);
}
}
Aggregations