aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorliujisi@google.com <liujisi@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2011-06-07 03:51:33 +0000
committerliujisi@google.com <liujisi@google.com@630680e5-0e50-0410-840e-4b1c322b438d>2011-06-07 03:51:33 +0000
commit3239fec94cdd7876130b87070d2d71148d9ef50b (patch)
tree1c4794621bf75557a5174b5495806fbc9e09cfd3 /examples
parente8e6eed0bed9db46b71fb79f8582680f8b09191a (diff)
downloadprotobuf-3239fec94cdd7876130b87070d2d71148d9ef50b.tar.gz
protobuf-3239fec94cdd7876130b87070d2d71148d9ef50b.tar.bz2
protobuf-3239fec94cdd7876130b87070d2d71148d9ef50b.zip
Close resources properly for java tests and examples.
Diffstat (limited to 'examples')
-rw-r--r--examples/AddPerson.java14
1 files changed, 10 insertions, 4 deletions
diff --git a/examples/AddPerson.java b/examples/AddPerson.java
index 4917684b..ca5ac273 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();
+ }
}
}