From 87df1d49bee37a9598eb31ef2ff1eca91a68ab65 Mon Sep 17 00:00:00 2001 From: daRoof <35702045+daRoof@users.noreply.github.com> Date: Fri, 1 Feb 2019 00:02:15 +0100 Subject: [PATCH] Closed resource leak The input streams were never closed - fixed that, using ancient Java style. --- .../freehep/graphicsio/emf/test/EMFDump.java | 53 ++++++++++++------- 1 file changed, 35 insertions(+), 18 deletions(-) diff --git a/freehep-graphicsio-emf/src/test/java/org/freehep/graphicsio/emf/test/EMFDump.java b/freehep-graphicsio-emf/src/test/java/org/freehep/graphicsio/emf/test/EMFDump.java index 64584ba2..4837f050 100644 --- a/freehep-graphicsio-emf/src/test/java/org/freehep/graphicsio/emf/test/EMFDump.java +++ b/freehep-graphicsio-emf/src/test/java/org/freehep/graphicsio/emf/test/EMFDump.java @@ -15,24 +15,41 @@ public class EMFDump { public static void main(String[] args) { + FileInputStream fis = null; + EMFInputStream emf = null; - try { - FileInputStream fis = new FileInputStream(args[0]); - EMFInputStream emf = new EMFInputStream(fis); - - long start = System.currentTimeMillis(); - EMFHeader header = emf.readHeader(); - System.out.println(header); - - Tag tag = emf.readTag(); - while (tag != null) { - System.out.println(tag); - tag = emf.readTag(); - } - System.out.println("Parsed file in: " - + (System.currentTimeMillis() - start) + " ms."); - } catch (IOException e) { - e.printStackTrace(); - } + try { + fis = new FileInputStream(args[0]); + emf = new EMFInputStream(fis); + + long start = System.currentTimeMillis(); + EMFHeader header = emf.readHeader(); + System.out.println(header); + + Tag tag = null; + do { + tag = emf.readTag(); + System.out.println(tag); + + if (tag instanceof EOF) { + // stop on End Of File tag + break; + } + } while (tag != null); + + System.out.println("Parsed file in: " + (System.currentTimeMillis() - start) + " ms."); + } catch (IOException e) { + e.printStackTrace(); + } finally { + try { + if (null != emf) { + emf.close(); + } else if (null != fis) { + fis.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + } } }