diff options
author | Marc Hoffmann <marc.hoffmann@sbb.ch> | 2013-01-08 17:12:23 +0100 |
---|---|---|
committer | Marc Hoffmann <marc.hoffmann@sbb.ch> | 2013-01-08 17:12:23 +0100 |
commit | 113816bd78744e268b58cdb496c2b1131849eb14 (patch) | |
tree | b136776449212ef8bfd79164e6828fd468c8965a /org.jacoco.agent.rt | |
parent | 538dc38bbc0d8b3d7c01f053ac232e84a1cf34e2 (diff) | |
download | jacoco-113816bd78744e268b58cdb496c2b1131849eb14.tar.gz |
Do not keep output file open.
Diffstat (limited to 'org.jacoco.agent.rt')
-rw-r--r-- | org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/controller/LocalController.java | 27 |
1 files changed, 19 insertions, 8 deletions
diff --git a/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/controller/LocalController.java b/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/controller/LocalController.java index c6ced00c..9e01e67d 100644 --- a/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/controller/LocalController.java +++ b/org.jacoco.agent.rt/src/org/jacoco/agent/rt/internal/controller/LocalController.java @@ -11,7 +11,6 @@ *******************************************************************************/ package org.jacoco.agent.rt.internal.controller; -import java.io.BufferedOutputStream; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -33,27 +32,39 @@ public class LocalController implements IAgentController { private RuntimeData data; - private OutputStream output; + private File destFile; + + private boolean append; public final void startup(final AgentOptions options, final RuntimeData data) throws IOException { this.data = data; - final File destFile = new File(options.getDestfile()).getAbsoluteFile(); + this.destFile = new File(options.getDestfile()).getAbsoluteFile(); + this.append = options.getAppend(); final File folder = destFile.getParentFile(); if (folder != null) { folder.mkdirs(); } - output = new BufferedOutputStream(new FileOutputStream(destFile, - options.getAppend())); + // Make sure we can write to the file: + openFile().close(); } public void writeExecutionData(final boolean reset) throws IOException { - final ExecutionDataWriter writer = new ExecutionDataWriter(output); - data.collect(writer, writer, reset); + final OutputStream output = openFile(); + try { + final ExecutionDataWriter writer = new ExecutionDataWriter(output); + data.collect(writer, writer, reset); + } finally { + output.close(); + } } public void shutdown() throws IOException { - output.close(); + // Nothing to do + } + + private OutputStream openFile() throws IOException { + return new FileOutputStream(destFile, append); } } |