summaryrefslogtreecommitdiff
path: root/xmerge
diff options
context:
space:
mode:
authorRobert Antoni Buj i Gelonch <robert.buj@gmail.com>2014-10-15 21:48:19 +0200
committerNoel Grandin <noelgrandin@gmail.com>2014-10-16 10:25:18 +0000
commitbbd5a304112c57ac1b1357c93ba7bd8ed8973cfa (patch)
tree486ed529cd19a3050c476c5f5f54c3afab808ce9 /xmerge
parentd49eabcc56677553a6d5d9fe7cecc5a5eee1f9b6 (diff)
java: ensure that the stream is cleaned up before the method returns
Change-Id: Id3efeda2fd66173ba2f5662eaacb3629da54573d Reviewed-on: https://gerrit.libreoffice.org/11991 Reviewed-by: Noel Grandin <noelgrandin@gmail.com> Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'xmerge')
-rw-r--r--xmerge/source/xmerge/java/org/openoffice/xmerge/util/ActiveSyncDriver.java61
-rw-r--r--xmerge/source/xmerge/java/org/openoffice/xmerge/util/Debug.java48
2 files changed, 59 insertions, 50 deletions
diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/util/ActiveSyncDriver.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/util/ActiveSyncDriver.java
index e10702a7de67..829963283e16 100644
--- a/xmerge/source/xmerge/java/org/openoffice/xmerge/util/ActiveSyncDriver.java
+++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/util/ActiveSyncDriver.java
@@ -21,11 +21,15 @@ package org.openoffice.xmerge.util;
import java.io.File;
import java.io.FileOutputStream;
import java.io.FileInputStream;
+import java.io.IOException;
+
import java.util.StringTokenizer;
+import java.util.NoSuchElementException;
import org.openoffice.xmerge.Convert;
import org.openoffice.xmerge.Document;
import org.openoffice.xmerge.ConvertData;
+import org.openoffice.xmerge.ConvertException;
import org.openoffice.xmerge.ConverterFactory;
import org.openoffice.xmerge.util.registry.ConverterInfoMgr;
import org.openoffice.xmerge.util.registry.ConverterInfoReader;
@@ -103,36 +107,37 @@ public class ActiveSyncDriver {
}
// Everything is registered so do the conversion
- FileInputStream fis = new FileInputStream(srcFile);
- FileOutputStream fos = new FileOutputStream(dstFile);
-
- conv.addInputStream(srcFile, fis);
-
- ConvertData dataOut;
+ boolean bOK = true;
+ FileInputStream fis = null;
+ FileOutputStream fos = null;
try {
- dataOut = conv.convert();
- }
- catch (Exception e) {
- fos.close();
- return false;
- }
-
- if (dataOut == null) {
- fos.close();
- return false;
- }
-
- // Get the document and write it out.
- Document doc = (Document)dataOut.getDocumentEnumeration().next();
- if (doc == null) {
- fos.close();
- return false;
+ fis = new FileInputStream(srcFile);
+ conv.addInputStream(srcFile, fis);
+ try {
+ fos = new FileOutputStream(dstFile);
+ ConvertData dataOut = conv.convert();
+
+ // Get the document and write it out.
+ Document doc = (Document)dataOut.getDocumentEnumeration().next();
+ doc.write(fos);
+ fos.flush();
+ } finally {
+ if (fos != null)
+ fos.close();
+ }
+ } catch (IOException e) {
+ bOK = false;
+ } catch (NullPointerException e) {
+ bOK = false;
+ } catch (ConvertException e) {
+ bOK = false;
+ } catch (NoSuchElementException e) {
+ bOK = false;
+ } finally {
+ if (fis != null)
+ fis.close();
}
- doc.write(fos);
- fos.flush();
- fos.close();
-
- return true;
+ return bOK;
}
} \ No newline at end of file
diff --git a/xmerge/source/xmerge/java/org/openoffice/xmerge/util/Debug.java b/xmerge/source/xmerge/java/org/openoffice/xmerge/util/Debug.java
index fe0429ea6ebd..50a34b2d4e95 100644
--- a/xmerge/source/xmerge/java/org/openoffice/xmerge/util/Debug.java
+++ b/xmerge/source/xmerge/java/org/openoffice/xmerge/util/Debug.java
@@ -53,38 +53,42 @@ public final class Debug {
static {
+ InputStream is = null;
try {
+ try {
+ is = Debug.class.getResourceAsStream("Debug.properties");
+ Properties props = new Properties();
+ props.load(is);
- InputStream is = Debug.class.getResourceAsStream("Debug.properties");
- Properties props = new Properties();
- props.load(is);
+ String info = props.getProperty("debug.info", "false");
+ info = info.toLowerCase();
- String info = props.getProperty("debug.info", "false");
- info = info.toLowerCase();
-
- if (info.equals("true")) {
- setFlags(Debug.INFO, Debug.SET);
- }
+ if (info.equals("true")) {
+ setFlags(Debug.INFO, Debug.SET);
+ }
- String trace = props.getProperty("debug.trace", "false");
- trace = trace.toLowerCase();
+ String trace = props.getProperty("debug.trace", "false");
+ trace = trace.toLowerCase();
- if (trace.equals("true")) {
- setFlags(Debug.TRACE, Debug.SET);
- }
+ if (trace.equals("true")) {
+ setFlags(Debug.TRACE, Debug.SET);
+ }
- String error = props.getProperty("debug.error", "false");
- error = error.toLowerCase();
+ String error = props.getProperty("debug.error", "false");
+ error = error.toLowerCase();
- if (error.equals("true")) {
- setFlags(Debug.ERROR, Debug.SET);
- }
+ if (error.equals("true")) {
+ setFlags(Debug.ERROR, Debug.SET);
+ }
- String w = props.getProperty("debug.output", "System.out");
- setOutput(w);
+ String w = props.getProperty("debug.output", "System.out");
+ setOutput(w);
+ } finally {
+ if (is !=null)
+ is.close();
+ }
} catch (Throwable ex) {
-
ex.printStackTrace(System.err);
}
}