From b00a99194e4a4dd30dbb2951d731b6e7a252dc86 Mon Sep 17 00:00:00 2001 From: Tiziano Lattisi Date: Fri, 28 Sep 2018 18:23:18 +0200 Subject: [PATCH] Fix dispose --- src/main/java/com/axiastudio/ooops/Ooops.java | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/axiastudio/ooops/Ooops.java b/src/main/java/com/axiastudio/ooops/Ooops.java index ff6cd08..9454cb9 100644 --- a/src/main/java/com/axiastudio/ooops/Ooops.java +++ b/src/main/java/com/axiastudio/ooops/Ooops.java @@ -385,6 +385,8 @@ public OutputStream stream(){ return outStream; } catch (com.sun.star.io.IOException ex) { Logger.getLogger(Ooops.class.getName()).log(Level.SEVERE, null, ex); + } finally { + close(); } return null; } @@ -403,6 +405,8 @@ public Boolean toUrl(String storeUrl){ return true; } catch (com.sun.star.io.IOException ex) { Logger.getLogger(Ooops.class.getName()).log(Level.SEVERE, null, ex); + } finally { + close(); } return null; } @@ -413,26 +417,32 @@ public Boolean toStream(OutputStream outputStream){ return Boolean.TRUE; } catch (java.io.IOException e) { e.printStackTrace(); + } finally { + close(); } return Boolean.FALSE; } public byte[] toByteArray() { OoopsOutputStream stream = (OoopsOutputStream) stream(); + close(); return stream.toByteArray(); } - private void disposeComponent() { - XCloseable closeable = UnoRuntime.queryInterface(XCloseable.class, component); - if (closeable != null) { - try { - closeable.close(true); - } catch (CloseVetoException e) { - } + private void close() { + XModel model = UnoRuntime.queryInterface(XModel.class, component); + if (model!=null) { + XCloseable closeable = UnoRuntime.queryInterface(XCloseable.class, model); + if (closeable != null) { + try { + closeable.close(true); + } catch (CloseVetoException e) { - } else { - component.dispose(); + } + } else { + component.dispose(); + } } }