Revision: 19748
          http://sourceforge.net/p/gate/code/19748
Author:   markagreenwood
Date:     2016-11-18 04:23:17 +0000 (Fri, 18 Nov 2016)
Log Message:
-----------
make sure we close streams even if we hit an exception

Modified Paths:
--------------
    
gate/branches/sawdust2/plugins/Tools/src/main/java/gate/creole/dumpingPR/DumpingPR.java

Modified: 
gate/branches/sawdust2/plugins/Tools/src/main/java/gate/creole/dumpingPR/DumpingPR.java
===================================================================
--- 
gate/branches/sawdust2/plugins/Tools/src/main/java/gate/creole/dumpingPR/DumpingPR.java
     2016-11-18 04:15:42 UTC (rev 19747)
+++ 
gate/branches/sawdust2/plugins/Tools/src/main/java/gate/creole/dumpingPR/DumpingPR.java
     2016-11-18 04:23:17 UTC (rev 19748)
@@ -28,6 +28,8 @@
 import java.util.Map;
 import java.util.Set;
 
+import org.apache.tika.io.IOUtils;
+
 import gate.Annotation;
 import gate.AnnotationSet;
 import gate.Gate;
@@ -231,9 +233,10 @@
         Out.prln(outputPath);
       outputFile = new File(outputPath);
 
+      OutputStreamWriter writer = null;
     try {
       // Prepare to write into the xmlFile using the doc's encoding if there
-      OutputStreamWriter writer;
+      
       if (document instanceof DocumentImpl) {
         String encoding = ((DocumentImpl) document).getEncoding();
         if (encoding == null || "".equals(encoding))
@@ -250,12 +253,14 @@
       // So, is for sure that the resource is a gate.Document
       writer.write(document.toXml(exportSet, includeFeatures));
       writer.flush();
-      writer.close();
     } catch (IOException ex) {
       throw new GateRuntimeException("Dumping PR: Error writing document "
                                      + document.getName() + ": "
                                      + ex.getMessage());
     }
+    finally {
+      if (writer != null) IOUtils.closeQuietly(writer);
+    }
 
 
   }//write2File
@@ -278,9 +283,10 @@
         Out.prln(outputPath);
       outputFile = new File(outputPath);
 
+      OutputStreamWriter writer = null;
     try {
       // Prepare to write into the xmlFile using the doc's encoding if there
-      OutputStreamWriter writer;
+      
       if (document instanceof DocumentImpl) {
         String encoding = ((DocumentImpl) document).getEncoding();
         if (encoding == null || "".equals(encoding))
@@ -297,12 +303,14 @@
       // So, is for sure that the resource is a gate.Document
       writer.write(document.toXml());
       writer.flush();
-      writer.close();
     } catch (IOException ex) {
       throw new GateRuntimeException("Dumping PR: Error writing document "
                                      + document.getName() + ": "
                                      + ex.getMessage());
     }
+    finally {
+      if (writer != null) IOUtils.closeQuietly(writer);
+    }
 
 
   }//write2File
@@ -411,7 +419,7 @@
   }
 
   public Boolean getIncludeFeatures() {
-    return new Boolean(includeFeatures);
+    return includeFeatures;
   }
 
   @Optional
@@ -422,7 +430,7 @@
   }
 
   public Boolean getUseStandOffXML() {
-    return new Boolean(useStandOffXML);
+    return useStandOffXML;
   }
 
   public String getSuffixForDumpFiles() {
@@ -436,7 +444,7 @@
   }
 
   public Boolean getUseSuffixForDumpFiles() {
-    return new Boolean(this.useSuffixForDumpFiles);
+    return useSuffixForDumpFiles;
   }
 
   @Optional

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
_______________________________________________
GATE-cvs mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gate-cvs

Reply via email to