Kaydet (Commit) bbd5a304 authored tarafından Robert Antoni Buj i Gelonch's avatar Robert Antoni Buj i Gelonch Kaydeden (comit) Noel Grandin

java: ensure that the stream is cleaned up before the method returns

Change-Id: Id3efeda2fd66173ba2f5662eaacb3629da54573d
Reviewed-on: https://gerrit.libreoffice.org/11991Reviewed-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
Tested-by: 's avatarNoel Grandin <noelgrandin@gmail.com>
üst d49eabcc
...@@ -868,9 +868,17 @@ public class FormControlTest extends complexlib.ComplexTestCase implements XSQLE ...@@ -868,9 +868,17 @@ public class FormControlTest extends complexlib.ComplexTestCase implements XSQLE
{ {
m_sImageURL = util.utils.getOfficeTempDir( m_orb ) + "image.gif"; m_sImageURL = util.utils.getOfficeTempDir( m_orb ) + "image.gif";
FileOutputStream aFile = new FileOutputStream( m_sImageURL ); FileOutputStream aFile = null;
aFile.write( getSamplePicture() ); try
aFile.close(); {
aFile = new FileOutputStream( m_sImageURL );
aFile.write( getSamplePicture() );
}
finally
{
if ( aFile != null )
aFile.close();
}
log.println( "created temporary image file: " + m_sImageURL ); log.println( "created temporary image file: " + m_sImageURL );
// for later setting the url at the imaghe control, we need a real URL, no system path // for later setting the url at the imaghe control, we need a real URL, no system path
......
...@@ -21,11 +21,15 @@ package org.openoffice.xmerge.util; ...@@ -21,11 +21,15 @@ package org.openoffice.xmerge.util;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.IOException;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import java.util.NoSuchElementException;
import org.openoffice.xmerge.Convert; import org.openoffice.xmerge.Convert;
import org.openoffice.xmerge.Document; import org.openoffice.xmerge.Document;
import org.openoffice.xmerge.ConvertData; import org.openoffice.xmerge.ConvertData;
import org.openoffice.xmerge.ConvertException;
import org.openoffice.xmerge.ConverterFactory; import org.openoffice.xmerge.ConverterFactory;
import org.openoffice.xmerge.util.registry.ConverterInfoMgr; import org.openoffice.xmerge.util.registry.ConverterInfoMgr;
import org.openoffice.xmerge.util.registry.ConverterInfoReader; import org.openoffice.xmerge.util.registry.ConverterInfoReader;
...@@ -103,36 +107,37 @@ public class ActiveSyncDriver { ...@@ -103,36 +107,37 @@ public class ActiveSyncDriver {
} }
// Everything is registered so do the conversion // Everything is registered so do the conversion
FileInputStream fis = new FileInputStream(srcFile); boolean bOK = true;
FileOutputStream fos = new FileOutputStream(dstFile); FileInputStream fis = null;
FileOutputStream fos = null;
conv.addInputStream(srcFile, fis);
ConvertData dataOut;
try { try {
dataOut = conv.convert(); fis = new FileInputStream(srcFile);
} conv.addInputStream(srcFile, fis);
catch (Exception e) { try {
fos.close(); fos = new FileOutputStream(dstFile);
return false; ConvertData dataOut = conv.convert();
}
// Get the document and write it out.
if (dataOut == null) { Document doc = (Document)dataOut.getDocumentEnumeration().next();
fos.close(); doc.write(fos);
return false; fos.flush();
} } finally {
if (fos != null)
// Get the document and write it out. fos.close();
Document doc = (Document)dataOut.getDocumentEnumeration().next(); }
if (doc == null) { } catch (IOException e) {
fos.close(); bOK = false;
return 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); return bOK;
fos.flush();
fos.close();
return true;
} }
} }
\ No newline at end of file
...@@ -53,38 +53,42 @@ public final class Debug { ...@@ -53,38 +53,42 @@ public final class Debug {
static { static {
InputStream is = null;
try { try {
try {
is = Debug.class.getResourceAsStream("Debug.properties");
Properties props = new Properties();
props.load(is);
InputStream is = Debug.class.getResourceAsStream("Debug.properties"); String info = props.getProperty("debug.info", "false");
Properties props = new Properties(); info = info.toLowerCase();
props.load(is);
String info = props.getProperty("debug.info", "false"); if (info.equals("true")) {
info = info.toLowerCase(); setFlags(Debug.INFO, Debug.SET);
}
if (info.equals("true")) {
setFlags(Debug.INFO, Debug.SET);
}
String trace = props.getProperty("debug.trace", "false"); String trace = props.getProperty("debug.trace", "false");
trace = trace.toLowerCase(); trace = trace.toLowerCase();
if (trace.equals("true")) { if (trace.equals("true")) {
setFlags(Debug.TRACE, Debug.SET); setFlags(Debug.TRACE, Debug.SET);
} }
String error = props.getProperty("debug.error", "false"); String error = props.getProperty("debug.error", "false");
error = error.toLowerCase(); error = error.toLowerCase();
if (error.equals("true")) { if (error.equals("true")) {
setFlags(Debug.ERROR, Debug.SET); setFlags(Debug.ERROR, Debug.SET);
} }
String w = props.getProperty("debug.output", "System.out"); String w = props.getProperty("debug.output", "System.out");
setOutput(w); setOutput(w);
} finally {
if (is !=null)
is.close();
}
} catch (Throwable ex) { } catch (Throwable ex) {
ex.printStackTrace(System.err); ex.printStackTrace(System.err);
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment