aboutsummaryrefslogtreecommitdiff
path: root/org.jacoco.core/src/org/jacoco/core/data/ExecutionDataReader.java
diff options
context:
space:
mode:
authorMarc R. Hoffmann <hoffmann@mountainminds.com>2011-03-10 15:28:21 +0000
committerMarc R. Hoffmann <hoffmann@mountainminds.com>2011-03-10 15:28:21 +0000
commit54e674c0ab96b93668e6c0b036e7773e3ed7ff6d (patch)
treef27b65a0121f35452939ba8976668d22aff5536e /org.jacoco.core/src/org/jacoco/core/data/ExecutionDataReader.java
parent7232b74441b829f41979433f2dee6883939de3fc (diff)
downloadjacoco-54e674c0ab96b93668e6c0b036e7773e3ed7ff6d.tar.gz
Trac #150: Allow empty exec files.
Diffstat (limited to 'org.jacoco.core/src/org/jacoco/core/data/ExecutionDataReader.java')
-rw-r--r--org.jacoco.core/src/org/jacoco/core/data/ExecutionDataReader.java22
1 files changed, 13 insertions, 9 deletions
diff --git a/org.jacoco.core/src/org/jacoco/core/data/ExecutionDataReader.java b/org.jacoco.core/src/org/jacoco/core/data/ExecutionDataReader.java
index b4dccaee..4afbc905 100644
--- a/org.jacoco.core/src/org/jacoco/core/data/ExecutionDataReader.java
+++ b/org.jacoco.core/src/org/jacoco/core/data/ExecutionDataReader.java
@@ -27,9 +27,11 @@ public class ExecutionDataReader {
/** Underlying data input */
protected final CompactDataInput in;
- private ISessionInfoVisitor sessionInfoVisitor;
+ private ISessionInfoVisitor sessionInfoVisitor = null;
- private IExecutionDataVisitor executionDataVisitor;
+ private IExecutionDataVisitor executionDataVisitor = null;
+
+ private boolean firstBlock = true;
/**
* Creates a new reader based on the given input stream input. Depending on
@@ -38,13 +40,9 @@ public class ExecutionDataReader {
*
* @param input
* input stream to read execution data from
- * @throws IOException
- * if the stream does not have a valid header
*/
- public ExecutionDataReader(final InputStream input) throws IOException {
+ public ExecutionDataReader(final InputStream input) {
this.in = new CompactDataInput(input);
- in.readByte();
- readHeader();
}
/**
@@ -77,8 +75,14 @@ public class ExecutionDataReader {
*/
public boolean read() throws IOException {
try {
- while (readBlock(in.readByte())) {
- }
+ byte type;
+ do {
+ type = in.readByte();
+ if (firstBlock && type != ExecutionDataWriter.BLOCK_HEADER) {
+ throw new IOException("Invalid execution data file.");
+ }
+ firstBlock = false;
+ } while (readBlock(type));
return true;
} catch (final EOFException e) {
return false;