content: /* Copyright (C) 2016-2018 Alibaba Group Holding Limited
  
  Licensed under the Apache License, Version 2.0 (the "License");
  you may not use this file except in compliance with the License.
  You may obtain a copy of the License at
  
      http://www.apache.org/licenses/LICENSE-2.0
  
  Unless required by applicable law or agreed to in writing, software
  distributed under the License is distributed on an "AS IS" BASIS,
  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  See the License for the specific language governing permissions and
  limitations under the License.
  ==============================================================================*/
  
  // 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;
            default:
              System.out.println(" Unknown 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);
    }
  }
  