forked from fdanismaz/java
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathApp.java
More file actions
29 lines (22 loc) · 971 Bytes
/
Copy pathApp.java
File metadata and controls
29 lines (22 loc) · 971 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.fd.protobuf;
import com.fd.protobuf.proto.AddressBookProtos;
import java.io.*;
public class App {
public static void main(String[] args) throws IOException {
AddressBookProtos.Person furkan = AddressBookProtos.Person.newBuilder()
.setId(123)
.setName("furkan danismaz")
.setEmail("...")
.addPhones(
AddressBookProtos.Person.PhoneNumber.newBuilder()
.setNumber("555-1234")
.setType(AddressBookProtos.Person.PhoneType.MOBILE)
.build())
.build();
OutputStream os = new FileOutputStream(new File("./output"));
furkan.writeTo(os);
InputStream is = new FileInputStream(new File("./output"));
AddressBookProtos.Person parsedPerson = AddressBookProtos.Person.parseFrom(is);
System.out.println(parsedPerson);
}
}