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
{
m_sImageURL = util.utils.getOfficeTempDir( m_orb ) + "image.gif";
FileOutputStream aFile = new FileOutputStream( m_sImageURL );
aFile.write( getSamplePicture() );
aFile.close();
FileOutputStream aFile = null;
try
{
aFile = new FileOutputStream( m_sImageURL );
aFile.write( getSamplePicture() );
}
finally
{
if ( aFile != null )
aFile.close();
}
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
......
......@@ -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
......@@ -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);
}
}
......
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