diff options
| author | Jørgen P. Tjernø <[email protected]> | 2013-12-03 10:39:23 -0800 |
|---|---|---|
| committer | Jørgen P. Tjernø <[email protected]> | 2013-12-03 11:57:22 -0800 |
| commit | b5dc4a85433a908d38d453e98d7d45e22e2a5fc0 (patch) | |
| tree | f186094efa03e9c1144fb5c98161cf3f7b054f90 /sp/src/thirdparty/protobuf-2.3.0/examples/AddPerson.java | |
| parent | Specify clobbered registers in POSIX SSE functions (diff) | |
| download | source-sdk-2013-b5dc4a85433a908d38d453e98d7d45e22e2a5fc0.tar.xz source-sdk-2013-b5dc4a85433a908d38d453e98d7d45e22e2a5fc0.zip | |
Line-ending fixes for most of the remaining files.
Fixes line-endings for files with extensions vcd, cc, txt, bat, fxc, inc, lst,
proto, mak, mm, cfg, res, rc, def, vmt, vsh, vbsp, inl, asm, m4, vcproj,
vcxproj, sln, in, java, la, manifest, am, and rad.
Also fixes README, CONTRIBUTING, CONTRIBUTORS, LICENSE, CHANGES, COPYING, and
gitignore.
Finally, fixes executable bits.
Diffstat (limited to 'sp/src/thirdparty/protobuf-2.3.0/examples/AddPerson.java')
| -rw-r--r-- | sp/src/thirdparty/protobuf-2.3.0/examples/AddPerson.java | 178 |
1 files changed, 89 insertions, 89 deletions
diff --git a/sp/src/thirdparty/protobuf-2.3.0/examples/AddPerson.java b/sp/src/thirdparty/protobuf-2.3.0/examples/AddPerson.java index 48045ec3..4917684b 100644 --- a/sp/src/thirdparty/protobuf-2.3.0/examples/AddPerson.java +++ b/sp/src/thirdparty/protobuf-2.3.0/examples/AddPerson.java @@ -1,89 +1,89 @@ -// See README.txt for information and build instructions.
-
-import com.example.tutorial.AddressBookProtos.AddressBook;
-import com.example.tutorial.AddressBookProtos.Person;
-import java.io.BufferedReader;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.InputStreamReader;
-import java.io.IOException;
-import java.io.PrintStream;
-
-class AddPerson {
- // This function fills in a Person message based on user input.
- static Person PromptForAddress(BufferedReader stdin,
- PrintStream stdout) throws IOException {
- Person.Builder person = Person.newBuilder();
-
- stdout.print("Enter person ID: ");
- person.setId(Integer.valueOf(stdin.readLine()));
-
- stdout.print("Enter name: ");
- person.setName(stdin.readLine());
-
- stdout.print("Enter email address (blank for none): ");
- String email = stdin.readLine();
- if (email.length() > 0) {
- person.setEmail(email);
- }
-
- while (true) {
- stdout.print("Enter a phone number (or leave blank to finish): ");
- String number = stdin.readLine();
- if (number.length() == 0) {
- break;
- }
-
- Person.PhoneNumber.Builder phoneNumber =
- Person.PhoneNumber.newBuilder().setNumber(number);
-
- stdout.print("Is this a mobile, home, or work phone? ");
- String type = stdin.readLine();
- if (type.equals("mobile")) {
- phoneNumber.setType(Person.PhoneType.MOBILE);
- } else if (type.equals("home")) {
- phoneNumber.setType(Person.PhoneType.HOME);
- } else if (type.equals("work")) {
- phoneNumber.setType(Person.PhoneType.WORK);
- } else {
- stdout.println("Unknown phone type. Using default.");
- }
-
- person.addPhone(phoneNumber);
- }
-
- return person.build();
- }
-
- // Main function: Reads the entire address book from a file,
- // adds one person based on user input, then writes it back out to the same
- // file.
- public static void main(String[] args) throws Exception {
- if (args.length != 1) {
- System.err.println("Usage: AddPerson ADDRESS_BOOK_FILE");
- System.exit(-1);
- }
-
- AddressBook.Builder addressBook = AddressBook.newBuilder();
-
- // Read the existing address book.
- try {
- FileInputStream input = new FileInputStream(args[0]);
- addressBook.mergeFrom(input);
- input.close();
- } catch (FileNotFoundException e) {
- System.out.println(args[0] + ": File not found. Creating a new file.");
- }
-
- // Add an address.
- addressBook.addPerson(
- PromptForAddress(new BufferedReader(new InputStreamReader(System.in)),
- System.out));
-
- // Write the new address book back to disk.
- FileOutputStream output = new FileOutputStream(args[0]);
- addressBook.build().writeTo(output);
- output.close();
- }
-}
+// See README.txt for information and build instructions. + +import com.example.tutorial.AddressBookProtos.AddressBook; +import com.example.tutorial.AddressBookProtos.Person; +import java.io.BufferedReader; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.InputStreamReader; +import java.io.IOException; +import java.io.PrintStream; + +class AddPerson { + // This function fills in a Person message based on user input. + static Person PromptForAddress(BufferedReader stdin, + PrintStream stdout) throws IOException { + Person.Builder person = Person.newBuilder(); + + stdout.print("Enter person ID: "); + person.setId(Integer.valueOf(stdin.readLine())); + + stdout.print("Enter name: "); + person.setName(stdin.readLine()); + + stdout.print("Enter email address (blank for none): "); + String email = stdin.readLine(); + if (email.length() > 0) { + person.setEmail(email); + } + + while (true) { + stdout.print("Enter a phone number (or leave blank to finish): "); + String number = stdin.readLine(); + if (number.length() == 0) { + break; + } + + Person.PhoneNumber.Builder phoneNumber = + Person.PhoneNumber.newBuilder().setNumber(number); + + stdout.print("Is this a mobile, home, or work phone? "); + String type = stdin.readLine(); + if (type.equals("mobile")) { + phoneNumber.setType(Person.PhoneType.MOBILE); + } else if (type.equals("home")) { + phoneNumber.setType(Person.PhoneType.HOME); + } else if (type.equals("work")) { + phoneNumber.setType(Person.PhoneType.WORK); + } else { + stdout.println("Unknown phone type. Using default."); + } + + person.addPhone(phoneNumber); + } + + return person.build(); + } + + // Main function: Reads the entire address book from a file, + // adds one person based on user input, then writes it back out to the same + // file. + public static void main(String[] args) throws Exception { + if (args.length != 1) { + System.err.println("Usage: AddPerson ADDRESS_BOOK_FILE"); + System.exit(-1); + } + + AddressBook.Builder addressBook = AddressBook.newBuilder(); + + // Read the existing address book. + try { + FileInputStream input = new FileInputStream(args[0]); + addressBook.mergeFrom(input); + input.close(); + } catch (FileNotFoundException e) { + System.out.println(args[0] + ": File not found. Creating a new file."); + } + + // Add an address. + addressBook.addPerson( + PromptForAddress(new BufferedReader(new InputStreamReader(System.in)), + System.out)); + + // Write the new address book back to disk. + FileOutputStream output = new FileOutputStream(args[0]); + addressBook.build().writeTo(output); + output.close(); + } +} |