aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core/src/org
diff options
context:
space:
mode:
authorMarc R. Hoffmann <hoffmann@mountainminds.com>2013-08-25 11:26:52 +0200
committerMarc R. Hoffmann <hoffmann@mountainminds.com>2013-08-25 11:26:52 +0200
commit3667815343ee12afebfae4e277f06e2f90660b7e (patch)
treee0c2ea7bcd9e4c34622f524ccfbbf5180b84ff8c /org.jacoco.core/src/org
parente368536569af3862e3f35a4b3cb095614e6e691c (diff)
downloadjacoco-3667815343ee12afebfae4e277f06e2f90660b7e.tar.gz
Add ExecFileLoader.save() methods for better code re-use.
Diffstat (limited to 'org.jacoco.core/src/org')
-rw-r--r--org.jacoco.core/src/org/jacoco/core/data/ExecFileLoader.java38
1 files changed, 38 insertions, 0 deletions
diff --git a/org.jacoco.core/src/org/jacoco/core/data/ExecFileLoader.java b/org.jacoco.core/src/org/jacoco/core/data/ExecFileLoader.java
index f6832f61..82713ce9 100644
--- a/org.jacoco.core/src/org/jacoco/core/data/ExecFileLoader.java
+++ b/org.jacoco.core/src/org/jacoco/core/data/ExecFileLoader.java
@@ -12,10 +12,13 @@
package org.jacoco.core.data;
import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.io.OutputStream;
/**
* Convenience utility for loading *.exec files into a
@@ -69,6 +72,41 @@ public class ExecFileLoader {
}
/**
+ * Saves the current content into the given output stream.
+ *
+ * @param stream
+ * stream to save content to
+ * @throws IOException
+ * in case of problems while writing to the stream
+ */
+ public void save(final OutputStream stream) throws IOException {
+ final ExecutionDataWriter dataWriter = new ExecutionDataWriter(stream);
+ sessionInfos.accept(dataWriter);
+ executionData.accept(dataWriter);
+ }
+
+ /**
+ * Saves the current content into the given file.
+ *
+ * @param file
+ * file to save content to
+ * @param append
+ * <code>true</code> if the content should be appended, otherwise
+ * the file is overwritten.
+ * @throws IOException
+ * in case of problems while writing to the stream
+ */
+ public void save(final File file, final boolean append) throws IOException {
+ final OutputStream stream = new BufferedOutputStream(
+ new FileOutputStream(file, append));
+ try {
+ save(stream);
+ } finally {
+ stream.close();
+ }
+ }
+
+ /**
* Returns the session info store with all loaded sessions.
*
* @return session info store