summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
Diffstat (limited to 'examples')
-rw-r--r--examples/AddPerson.java14
-rw-r--r--examples/list_people.cc1
2 files changed, 11 insertions, 4 deletions
diff --git a/examples/AddPerson.java b/examples/AddPerson.java
index 4917684..ca5ac27 100644
--- a/examples/AddPerson.java
+++ b/examples/AddPerson.java
@@ -70,8 +70,11 @@ class AddPerson {
// Read the existing address book.
try {
FileInputStream input = new FileInputStream(args[0]);
- addressBook.mergeFrom(input);
- input.close();
+ try {
+ addressBook.mergeFrom(input);
+ } finally {
+ try { input.close(); } catch (Throwable ignore) {}
+ }
} catch (FileNotFoundException e) {
System.out.println(args[0] + ": File not found. Creating a new file.");
}
@@ -83,7 +86,10 @@ class AddPerson {
// Write the new address book back to disk.
FileOutputStream output = new FileOutputStream(args[0]);
- addressBook.build().writeTo(output);
- output.close();
+ try {
+ addressBook.build().writeTo(output);
+ } finally {
+ output.close();
+ }
}
}
diff --git a/examples/list_people.cc b/examples/list_people.cc
index 5363152..d0f40d6 100644
--- a/examples/list_people.cc
+++ b/examples/list_people.cc
@@ -4,6 +4,7 @@
#include <fstream>
#include <string>
#include "addressbook.pb.h"
+#include <google/protobuf/io/zero_copy_stream_impl_lite.h>
using namespace std;
// Iterates though all people in the AddressBook and prints info about them.