[Libreoffice-commits] core.git: xmerge/source
jan iversen
jani at documentfoundation.org
Fri Nov 27 13:36:30 PST 2015
xmerge/source/bridge/java/XMergeBridge.java | 210 +++++++++++++---------------
1 file changed, 102 insertions(+), 108 deletions(-)
New commits:
commit 03c37cee476d14d1d8644ccc7ea5c69d74d9c7f9
Author: jan iversen <jani at documentfoundation.org>
Date: Thu Nov 5 15:19:56 2015 +0100
CID#1326472, CID#1326473, CID#1326474 use try/finalize
Coverity requires that closeable objects (use of new) call .close(),
git commit 5a29db7a9945c4cd095799451a6c563d5aeeed57
implemented a series of .close etc calls, update to
use a single try{}finalize{} instead.
Change-Id: Iadc9de13d6a0af4b0aaca2dfdd0e2d0940a5223d
Reviewed-on: https://gerrit.libreoffice.org/19807
Reviewed-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
Tested-by: Markus Mohrhard <markus.mohrhard at googlemail.com>
diff --git a/xmerge/source/bridge/java/XMergeBridge.java b/xmerge/source/bridge/java/XMergeBridge.java
index 391232c..bbe3e2a 100644
--- a/xmerge/source/bridge/java/XMergeBridge.java
+++ b/xmerge/source/bridge/java/XMergeBridge.java
@@ -375,136 +375,130 @@ public class XMergeBridge {
XInputStreamToInputStreamAdapter xis =new XInputStreamToInputStreamAdapter(xml);
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> ");
- }
- else
- {
- cv.addInputStream(name,xis,false);
- ConvertData dataOut = cv.convert();
+ /* make sure newxos and xis get closed */
+ try{
+ 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)
+ {
- Iterator<Object> docEnum = dataOut.getDocumentEnumeration();
+ try {
- if (docEnum.hasNext()){
- Document docOut = (Document)docEnum.next();
- docOut.write(newxos);
+ //Check to see if jar contains a plugin Impl
- newxos.flush();
- newxos.close();
+ ConverterInfoMgr.addPlugIn(ciEnum);
+ ConverterFactory cf = new ConverterFactory();
- int i=1;
- while (docEnum.hasNext() && sURL.startsWith("file:")) {
+ 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> ");
- 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) {
- /* Satisfy coverity */
- 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>");
+ catch (Exception ex1) {
+ IOException ex2 = new IOException();
+ ex2.initCause(ex1);
+ throw ex2;
}
- 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);
- ConvertData dataIn = cv.convert();
- Iterator<Object> docEnum = dataIn.getDocumentEnumeration();
- while (docEnum.hasNext()) {
- OfficeDocument docIn = (OfficeDocument)docEnum.next();
+ cv.addInputStream(name,xis,false);
+ ConvertData dataIn = cv.convert();
+ Iterator<Object> docEnum = dataIn.getDocumentEnumeration();
+ while (docEnum.hasNext()) {
+ 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.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){
More information about the Libreoffice-commits
mailing list