Mercurial > hg > truffle
changeset 2691:4149feada801
GraphvizPrinterObserver: close output stream also in case of exception
author | Peter Hofer <peter.hofer@jku.at> |
---|---|
date | Wed, 18 May 2011 11:27:10 +0200 |
parents | abb4cc15283d |
children | 79590d6b4a7c |
files | graal/GraalCompiler/src/com/sun/c1x/debug/GraphvizPrinterObserver.java |
diffstat | 1 files changed, 15 insertions(+), 9 deletions(-) [+] |
line wrap: on
line diff
--- a/graal/GraalCompiler/src/com/sun/c1x/debug/GraphvizPrinterObserver.java Wed May 18 11:53:06 2011 +0200 +++ b/graal/GraalCompiler/src/com/sun/c1x/debug/GraphvizPrinterObserver.java Wed May 18 11:27:10 2011 +0200 @@ -60,10 +60,12 @@ name = name.substring(1, name.length() - 1).replace('/', '.'); name = name + "." + event.getMethod().name(); String filename = name + "_" + (n++) + "_" + event.getLabel(); + + OutputStream out = null; try { if (pdf) { - ByteArrayOutputStream out = new ByteArrayOutputStream(); - GraphvizPrinter printer = new GraphvizPrinter(out); + ByteArrayOutputStream buffer = new ByteArrayOutputStream(); + GraphvizPrinter printer = new GraphvizPrinter(buffer); if (C1XOptions.OmitDOTFrameStates) { printer.addOmittedClass(FrameState.class); } @@ -71,24 +73,28 @@ printer.print(graph, true); printer.end(); - FileOutputStream output = new FileOutputStream(filename + ".pdf"); - GraphvizRunner.process(GraphvizRunner.DOT_LAYOUT, new ByteArrayInputStream(out.toByteArray()), output, "pdf"); - output.close(); + out = new FileOutputStream(filename + ".pdf"); + GraphvizRunner.process(GraphvizRunner.DOT_LAYOUT, new ByteArrayInputStream(buffer.toByteArray()), out, "pdf"); } else { - final FileOutputStream stream = new FileOutputStream(filename + ".gv"); + out = new FileOutputStream(filename + ".gv"); - GraphvizPrinter printer = new GraphvizPrinter(stream); + GraphvizPrinter printer = new GraphvizPrinter(out); if (C1XOptions.OmitDOTFrameStates) { printer.addOmittedClass(FrameState.class); } printer.begin(name); printer.print(graph, true); printer.end(); - - stream.close(); } } catch (IOException e) { e.printStackTrace(); + } finally { + if (out != null) { + try { + out.close(); + } catch (IOException e) { + } + } } } }