-
Notifications
You must be signed in to change notification settings - Fork 242
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix bug in BlockCompressedInputStream.checkTermination() (#1310)
* Fix bug in BlockCompressedInputStream.checkTermination() * Fixing a bug in BlockCompressedInputStream.checkTermination() The internal method readFully would throw in cases where less bytes were read than were available in the stream. We haven't observed this in practice but it's a valid behavior of SeekableByteChannel.read() so we should honor it. * Fixes #1251
- Loading branch information
1 parent
7b3c7a6
commit d678af3
Showing
5 changed files
with
57 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
src/test/java/htsjdk/testutil/streams/OneByteAtATimeChannel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package htsjdk.testutil.streams; | ||
|
||
import java.io.IOException; | ||
import java.nio.ByteBuffer; | ||
|
||
/** | ||
* A buffer backed channel that only reads 1 byte at a time on each read instance. Used for testing that read operations | ||
* work correctly when read returns less than the desired number of bytes and it isn't because of reaching EOF. | ||
*/ | ||
public class OneByteAtATimeChannel extends SeekableByteChannelFromBuffer { | ||
public OneByteAtATimeChannel(ByteBuffer buf) { | ||
super(buf); | ||
} | ||
|
||
@Override | ||
public int read(ByteBuffer dst) throws IOException { | ||
final ByteBuffer buf = getBuffer(); | ||
if (buf.position() == buf.limit()) { | ||
// signal EOF | ||
return -1; | ||
} | ||
int before = dst.position(); | ||
final byte oneByte = buf.get(); | ||
dst.put(oneByte); | ||
return dst.position() - before; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters