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@googlemail.com>
Tested-by: Markus Mohrhard <markus.mohrhard@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);

            /* make sure newxos and xis get closed */
            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{
                    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 {
                    try {

                    //Check to see if jar contains a plugin Impl
                        //Check to see if jar contains a plugin Impl

                    ConverterInfoMgr.addPlugIn(ciEnum);
                    ConverterFactory cf = new ConverterFactory();
                        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> ");
                        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();
                        }
                        else
                        {
                            cv.addInputStream(name,xis,false);
                            ConvertData dataOut = cv.convert();

                        Iterator<Object> docEnum = dataOut.getDocumentEnumeration();
                            Iterator<Object> docEnum = dataOut.getDocumentEnumeration();

                        if (docEnum.hasNext()){
                            Document docOut      = (Document)docEnum.next();
                            docOut.write(newxos);
                            if (docEnum.hasNext()){
                                Document docOut      = (Document)docEnum.next();
                                docOut.write(newxos);

                            newxos.flush();
                            newxos.close();
                                newxos.flush();
                                newxos.close();
                                newxos = null;

                            int i=1;
                            while (docEnum.hasNext() && sURL.startsWith("file:")) {
                                int i=1;
                                while (docEnum.hasNext() && sURL.startsWith("file:")) {

                                URI uri=new URI(sURL);
                                String  newFileName= getPath(uri);
                                    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(".")));
                                    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++;

                                }
                                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();
                        ex2.initCause(ex1);
                        throw ex2;
                    }
                }
                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>");
                        }
                        else
                        {

                            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);
                            }
                            newxos.close();
                            newxos = null;
                        }
                        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 (Exception ex1) {
                        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
                    {

                        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);
                        }
                        newxos.close();
                    }
                    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 (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){