From 30b937d2af93f5f943c1470a6cb8c7523a68acca Mon Sep 17 00:00:00 2001 From: Matt Hanna Date: Wed, 1 Feb 2012 16:06:22 -0500 Subject: [PATCH] Fix bug discovered in FGTP branch in which BlockInputStream returns -1 in cases where some data could be read, but not all the data requested by the caller. --- .../gatk/datasources/reads/BlockInputStream.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/BlockInputStream.java b/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/BlockInputStream.java index a95eb7b8e..cb37bad31 100644 --- a/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/BlockInputStream.java +++ b/public/java/src/org/broadinstitute/sting/gatk/datasources/reads/BlockInputStream.java @@ -443,7 +443,16 @@ public class BlockInputStream extends SeekableStream implements BAMInputStream { // } // } - return eof() ? -1 : length-remaining; + // If any data was copied into the buffer, return the amount of data copied. + if(remaining < length) + return length - remaining; + + // Otherwise, if at eof(), return -1. + else if(eof()) + return -1; + + // Otherwise, we must've hit a bug in the system. + throw new ReviewedStingException("BUG: read returned no data, but eof() reports false."); } public void close() {