Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(622)

Side by Side Diff: third_party/protobuf/examples/ListPeople.java

Issue 1842653006: Update //third_party/protobuf to version 3. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: merge Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « third_party/protobuf/examples/AddPerson.java ('k') | third_party/protobuf/examples/README.txt » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // See README.txt for information and build instructions.
2
3 import com.example.tutorial.AddressBookProtos.AddressBook;
4 import com.example.tutorial.AddressBookProtos.Person;
5 import java.io.FileInputStream;
6 import java.io.IOException;
7 import java.io.PrintStream;
8
9 class ListPeople {
10 // Iterates though all people in the AddressBook and prints info about them.
11 static void Print(AddressBook addressBook) {
12 for (Person person: addressBook.getPeopleList()) {
13 System.out.println("Person ID: " + person.getId());
14 System.out.println(" Name: " + person.getName());
15 if (!person.getEmail().isEmpty()) {
16 System.out.println(" E-mail address: " + person.getEmail());
17 }
18
19 for (Person.PhoneNumber phoneNumber : person.getPhonesList()) {
20 switch (phoneNumber.getType()) {
21 case MOBILE:
22 System.out.print(" Mobile phone #: ");
23 break;
24 case HOME:
25 System.out.print(" Home phone #: ");
26 break;
27 case WORK:
28 System.out.print(" Work phone #: ");
29 break;
30 }
31 System.out.println(phoneNumber.getNumber());
32 }
33 }
34 }
35
36 // Main function: Reads the entire address book from a file and prints all
37 // the information inside.
38 public static void main(String[] args) throws Exception {
39 if (args.length != 1) {
40 System.err.println("Usage: ListPeople ADDRESS_BOOK_FILE");
41 System.exit(-1);
42 }
43
44 // Read the existing address book.
45 AddressBook addressBook =
46 AddressBook.parseFrom(new FileInputStream(args[0]));
47
48 Print(addressBook);
49 }
50 }
OLDNEW
« no previous file with comments | « third_party/protobuf/examples/AddPerson.java ('k') | third_party/protobuf/examples/README.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698