aboutsummaryrefslogtreecommitdiffhomepage
path: root/third_party/protobuf/3.2.0/examples/ListPeople.java
diff options
context:
space:
mode:
authorGravatar Carmi Grushko <carmi@google.com>2017-02-22 16:15:07 -0500
committerGravatar Kristina Chodorow <kchodorow@google.com>2017-02-23 16:57:35 -0500
commit2346f5a01561f695a2b2ba7655359d5020105077 (patch)
treef3fdb019459e912c42e5209e325047023907268c /third_party/protobuf/3.2.0/examples/ListPeople.java
parent10390f2dac277baeaaff48fbfd663ce687ec92e1 (diff)
Upgrade //third_party/protobuf to v3.2.0
with some backports from HEAD (:java_toolchain, internal_gen_well_known_protos_java) Change-Id: I54be8809f411ec8cb02203b478f699e1fccb5f62
Diffstat (limited to 'third_party/protobuf/3.2.0/examples/ListPeople.java')
-rw-r--r--third_party/protobuf/3.2.0/examples/ListPeople.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/third_party/protobuf/3.2.0/examples/ListPeople.java b/third_party/protobuf/3.2.0/examples/ListPeople.java
new file mode 100644
index 0000000000..7892430508
--- /dev/null
+++ b/third_party/protobuf/3.2.0/examples/ListPeople.java
@@ -0,0 +1,50 @@
+// See README.txt for information and build instructions.
+
+import com.example.tutorial.AddressBookProtos.AddressBook;
+import com.example.tutorial.AddressBookProtos.Person;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.PrintStream;
+
+class ListPeople {
+ // Iterates though all people in the AddressBook and prints info about them.
+ static void Print(AddressBook addressBook) {
+ for (Person person: addressBook.getPeopleList()) {
+ System.out.println("Person ID: " + person.getId());
+ System.out.println(" Name: " + person.getName());
+ if (!person.getEmail().isEmpty()) {
+ System.out.println(" E-mail address: " + person.getEmail());
+ }
+
+ for (Person.PhoneNumber phoneNumber : person.getPhonesList()) {
+ switch (phoneNumber.getType()) {
+ case MOBILE:
+ System.out.print(" Mobile phone #: ");
+ break;
+ case HOME:
+ System.out.print(" Home phone #: ");
+ break;
+ case WORK:
+ System.out.print(" Work phone #: ");
+ break;
+ }
+ System.out.println(phoneNumber.getNumber());
+ }
+ }
+ }
+
+ // Main function: Reads the entire address book from a file and prints all
+ // the information inside.
+ public static void main(String[] args) throws Exception {
+ if (args.length != 1) {
+ System.err.println("Usage: ListPeople ADDRESS_BOOK_FILE");
+ System.exit(-1);
+ }
+
+ // Read the existing address book.
+ AddressBook addressBook =
+ AddressBook.parseFrom(new FileInputStream(args[0]));
+
+ Print(addressBook);
+ }
+}