@Override public void listLogEntries( ListLogEntriesRequest request, StreamObserver<ListLogEntriesResponse> responseObserver) { List<LogEntry> entries = new ArrayList<>(); for (ByteString proj : request.getProjectIdsList().asByteStringList()) { String prefix = "projects/" + proj.toStringUtf8() + "/"; for (Map.Entry<String, List<LogEntry>> entry : logs.entrySet()) { if (entry.getKey().startsWith(prefix)) { entries.addAll(entry.getValue()); } } } responseObserver.onNext(ListLogEntriesResponse.newBuilder().addAllEntries(entries).build()); responseObserver.onCompleted(); }
/** * Demonstrates using the Text to Speech client to list the client's supported voices. * @throws Exception on TextToSpeechClient Errors. */ public static void listAllSupportedVoices() throws Exception { // Instantiates a client try (TextToSpeechClient textToSpeechClient = TextToSpeechClient.create()) { // Builds the text to speech list voices request ListVoicesRequest request = ListVoicesRequest.getDefaultInstance(); // Performs the list voices request ListVoicesResponse response = textToSpeechClient.listVoices(request); List<Voice> voices = response.getVoicesList(); for (Voice voice : voices) { // Display the voice's name. Example: tpc-vocoded System.out.format("Name: %s\n", voice.getName()); // Display the supported language codes for this voice. Example: "en-us" List<ByteString> languageCodes = voice.getLanguageCodesList().asByteStringList(); for (ByteString languageCode : languageCodes) { System.out.format("Supported Language: %s\n", languageCode.toStringUtf8()); } // Display the SSML Voice Gender System.out.format("SSML Voice Gender: %s\n", voice.getSsmlGender()); // Display the natural sample rate hertz for this voice. Example: 24000 System.out.format("Natural Sample Rate Hertz: %s\n\n", voice.getNaturalSampleRateHertz()); } } } // [END tts_list_voices]
public static List<String> fromPBStringList(com.google.protobuf.ProtocolStringList groupbyFieldsList) { List<String> result = new ArrayList<>(groupbyFieldsList.size()); for(ByteString byteString:groupbyFieldsList.asByteStringList()){ result.add(byteString.toStringUtf8()); } return result; }
.getDependencyList().size()]; int i = 0; for (ByteString dependency : descriptorProto.getDependencyList().asByteStringList()) { String dependencyKey = dependency.toStringUtf8(); if (descMap.containsKey(dependencyKey)) {
private Descriptors.FileDescriptor getFileDescriptor(String rootDescriptor, BMap<String, BValue> descriptorMap) throws InvalidProtocolBufferException, Descriptors.DescriptorValidationException { byte[] descriptor = hexStringToByteArray(rootDescriptor); if (descriptor.length == 0) { throw new ClientRuntimeException("Error while reading the service proto descriptor. input descriptor " + "string is null."); } DescriptorProtos.FileDescriptorProto descriptorProto = DescriptorProtos.FileDescriptorProto.parseFrom (descriptor); if (descriptorProto == null) { throw new ClientRuntimeException("Error while reading the service proto descriptor. File proto descriptor" + " is null."); } Descriptors.FileDescriptor[] fileDescriptors = new Descriptors.FileDescriptor[descriptorProto .getDependencyList().size()]; int i = 0; for (ByteString dependency : descriptorProto.getDependencyList().asByteStringList()) { if (descriptorMap.hasKey(dependency.toStringUtf8())) { fileDescriptors[i++] = getFileDescriptor(descriptorMap.get(dependency.toString(Charset.forName ("UTF8"))).stringValue(), descriptorMap); } } if (fileDescriptors.length > 0 && i == 0) { throw new ClientRuntimeException("Error while reading the service proto descriptor. Couldn't find any " + "dependent descriptors."); } return Descriptors.FileDescriptor.buildFrom(descriptorProto, fileDescriptors); }