Repository: opennlp
Updated Branches:
  refs/heads/trunk 477de7f77 -> 895975eab


Use try with resources to write dictionary

See issue OPENNLP-872


Project: http://git-wip-us.apache.org/repos/asf/opennlp/repo
Commit: http://git-wip-us.apache.org/repos/asf/opennlp/commit/895975ea
Tree: http://git-wip-us.apache.org/repos/asf/opennlp/tree/895975ea
Diff: http://git-wip-us.apache.org/repos/asf/opennlp/diff/895975ea

Branch: refs/heads/trunk
Commit: 895975eab3691e4d85028feec859fa20dc2cac16
Parents: 477de7f
Author: Jörn Kottmann <[email protected]>
Authored: Wed Nov 2 22:36:01 2016 +0100
Committer: Jörn Kottmann <[email protected]>
Committed: Wed Nov 2 22:36:01 2016 +0100

----------------------------------------------------------------------
 .../namefind/CensusDictionaryCreatorTool.java        | 15 +--------------
 1 file changed, 1 insertion(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/opennlp/blob/895975ea/opennlp-tools/src/main/java/opennlp/tools/cmdline/namefind/CensusDictionaryCreatorTool.java
----------------------------------------------------------------------
diff --git 
a/opennlp-tools/src/main/java/opennlp/tools/cmdline/namefind/CensusDictionaryCreatorTool.java
 
b/opennlp-tools/src/main/java/opennlp/tools/cmdline/namefind/CensusDictionaryCreatorTool.java
index c3132f0..6798938 100644
--- 
a/opennlp-tools/src/main/java/opennlp/tools/cmdline/namefind/CensusDictionaryCreatorTool.java
+++ 
b/opennlp-tools/src/main/java/opennlp/tools/cmdline/namefind/CensusDictionaryCreatorTool.java
@@ -127,24 +127,11 @@ public class CensusDictionaryCreatorTool extends 
BasicCmdLineTool {
 
     System.out.println("Saving Dictionary...");
 
-    OutputStream out = null;
-
-    try {
-      out = new FileOutputStream(dictOutFile);
+    try (OutputStream out = new FileOutputStream(dictOutFile)) {
       mDictionary.serialize(out);
     } catch (IOException e) {
       throw new TerminateToolException(-1, "IO error while writing dictionary 
file: "
           + e.getMessage(), e);
     }
-    finally {
-      if (out != null)
-        try {
-          out.close();
-        } catch (IOException e) {
-          // file might be damaged
-          throw new TerminateToolException(-1, "Attention: Failed to correctly 
write dictionary:" +
-              e.getMessage(), e);
-        }
-    }
   }
 }

Reply via email to