Kaydet (Commit) 03c37cee authored tarafından jan iversen's avatar jan iversen Kaydeden (comit) Markus Mohrhard

CID#1326472, CID#1326473, CID#1326474 use try/finalize

Coverity requires that closeable objects (use of new) call .close(),

git commit 5a29db7a
implemented a series of .close etc calls, update to
use a single try{}finalize{} instead.

Change-Id: Iadc9de13d6a0af4b0aaca2dfdd0e2d0940a5223d
Reviewed-on: https://gerrit.libreoffice.org/19807Reviewed-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
Tested-by: 's avatarMarkus Mohrhard <markus.mohrhard@googlemail.com>
üst bc7a490a
...@@ -375,136 +375,130 @@ public class XMergeBridge { ...@@ -375,136 +375,130 @@ public class XMergeBridge {
XInputStreamToInputStreamAdapter xis =new XInputStreamToInputStreamAdapter(xml); XInputStreamToInputStreamAdapter xis =new XInputStreamToInputStreamAdapter(xml);
XOutputStreamToOutputStreamAdapter newxos =new XOutputStreamToOutputStreamAdapter(device); XOutputStreamToOutputStreamAdapter newxos =new XOutputStreamToOutputStreamAdapter(device);
try{
ConverterInfoReader cir = new ConverterInfoReader(jarName,false);
ciEnum =cir.getConverterInfoEnumeration();
}
catch (ParserConfigurationException pexc){
System.out.println("Error:"+pexc);
}
catch ( org.xml.sax.SAXException pexc){
System.out.println("Error:"+pexc);
}
catch(Exception e){
System.out.println("Error:"+e);
}
ConverterInfoMgr. removeByJar(jarName);
if (convertFromOffice)
{
try {
//Check to see if jar contains a plugin Impl
ConverterInfoMgr.addPlugIn(ciEnum);
ConverterFactory cf = new ConverterFactory();
Convert cv = cf.getConverter(ConverterInfoMgr.findConverterInfo(sdMime,offMime),false);
if (cv == null) {
System.out.println("\nNo plug-in exists to convert from <staroffice/sxw> to <specified format> ");
} /* make sure newxos and xis get closed */
else try{
{ try{
cv.addInputStream(name,xis,false); ConverterInfoReader cir = new ConverterInfoReader(jarName,false);
ConvertData dataOut = cv.convert(); ciEnum =cir.getConverterInfoEnumeration();
}
catch (ParserConfigurationException pexc){
System.out.println("Error:"+pexc);
}
catch ( org.xml.sax.SAXException pexc){
System.out.println("Error:"+pexc);
}
catch(Exception e){
System.out.println("Error:"+e);
}
ConverterInfoMgr. removeByJar(jarName);
if (convertFromOffice)
{
Iterator<Object> docEnum = dataOut.getDocumentEnumeration(); try {
if (docEnum.hasNext()){ //Check to see if jar contains a plugin Impl
Document docOut = (Document)docEnum.next();
docOut.write(newxos);
newxos.flush(); ConverterInfoMgr.addPlugIn(ciEnum);
newxos.close(); ConverterFactory cf = new ConverterFactory();
int i=1; Convert cv = cf.getConverter(ConverterInfoMgr.findConverterInfo(sdMime,offMime),false);
while (docEnum.hasNext() && sURL.startsWith("file:")) { if (cv == null) {
System.out.println("\nNo plug-in exists to convert from <staroffice/sxw> to <specified format> ");
URI uri=new URI(sURL); }
String newFileName= getPath(uri); else
{
cv.addInputStream(name,xis,false);
ConvertData dataOut = cv.convert();
Iterator<Object> docEnum = dataOut.getDocumentEnumeration();
if (docEnum.hasNext()){
Document docOut = (Document)docEnum.next();
docOut.write(newxos);
newxos.flush();
newxos.close();
newxos = null;
int i=1;
while (docEnum.hasNext() && sURL.startsWith("file:")) {
URI uri=new URI(sURL);
String newFileName= getPath(uri);
File newFile;
if (newFileName.lastIndexOf(".")!=-1){
newFile =new File(newFileName.substring(0,newFileName.lastIndexOf("."))+String.valueOf(i)+newFileName.substring(newFileName.lastIndexOf(".")));
}
else{
newFile =new File(newFileName.concat(String.valueOf(i)));
}
FileOutputStream fos = new FileOutputStream(newFile);
docOut = (Document)docEnum.next();
docOut.write(fos);
fos.flush();
fos.close();
i++;
File newFile;
if (newFileName.lastIndexOf(".")!=-1){
newFile =new File(newFileName.substring(0,newFileName.lastIndexOf("."))+String.valueOf(i)+newFileName.substring(newFileName.lastIndexOf(".")));
} }
else{
newFile =new File(newFileName.concat(String.valueOf(i)));
}
FileOutputStream fos = new FileOutputStream(newFile);
docOut = (Document)docEnum.next();
docOut.write(fos);
fos.flush();
fos.close();
fos = null;
i++;
} }
} }
ConverterInfoMgr.removeByJar(jarName);
} }
ConverterInfoMgr.removeByJar(jarName); catch (Exception ex1) {
} IOException ex2 = new IOException();
catch (Exception ex1) { ex2.initCause(ex1);
/* Satisfy coverity */ throw ex2;
newxos.flush();
newxos.close();
newxos = null;
xis.close();
xis = null;
IOException ex2 = new IOException();
ex2.initCause(ex1);
throw ex2;
}
}
else{
try {
//Check to see if jar contains a plugin Impl
ConverterInfoMgr.addPlugIn(ciEnum);
ConverterFactory cf = new ConverterFactory();
Convert cv = cf.getConverter(ConverterInfoMgr.findConverterInfo(sdMime,offMime),true);
if (cv == null) {
System.out.println("\nNo plug-in exists to convert to <staroffice/sxw> from <specified format>");
} }
else }
{ else{
try {
//Check to see if jar contains a plugin Impl
ConverterInfoMgr.addPlugIn(ciEnum);
ConverterFactory cf = new ConverterFactory();
Convert cv = cf.getConverter(ConverterInfoMgr.findConverterInfo(sdMime,offMime),true);
if (cv == null) {
System.out.println("\nNo plug-in exists to convert to <staroffice/sxw> from <specified format>");
}
else
{
cv.addInputStream(name,xis,false); cv.addInputStream(name,xis,false);
ConvertData dataIn = cv.convert(); ConvertData dataIn = cv.convert();
Iterator<Object> docEnum = dataIn.getDocumentEnumeration(); Iterator<Object> docEnum = dataIn.getDocumentEnumeration();
while (docEnum.hasNext()) { while (docEnum.hasNext()) {
OfficeDocument docIn = (OfficeDocument)docEnum.next(); OfficeDocument docIn = (OfficeDocument)docEnum.next();
docIn.write(newxos,false); docIn.write(newxos,false);
}
newxos.close();
newxos = null;
} }
newxos.close(); ConverterInfoMgr.removeByJar(jarName);
} }
ConverterInfoMgr.removeByJar(jarName); catch (StackOverflowError sOE){
} System.out.println("\nERROR : Stack Overflow. \n Increase of the JRE by adding the following line to the end of the javarc file \n \"-Xss1m\"\n");
catch (StackOverflowError sOE){ }
System.out.println("\nERROR : Stack Overflow. \n Increase of the JRE by adding the following line to the end of the javarc file \n \"-Xss1m\"\n"); catch (Exception ex1) {
IOException ex2 = new IOException();
ex2.initCause(ex1);
throw ex2;
}
} }
catch (Exception ex1) { }
/* Satisfy coverity */ finally{
if (newxos != null){
newxos.flush(); newxos.flush();
newxos.close(); newxos.close();
newxos = null;
xis.close();
xis = null;
IOException ex2 = new IOException();
ex2.initCause(ex1);
throw ex2;
} }
xis.close();
} }
/* Satisfy coverity */
newxos.flush();
newxos.close();
newxos = null;
xis.close();
xis = null;
} }
private String getPath(URI uri){ private String getPath(URI uri){
......
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