Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixing bug in SeekableHttpStream.read #1182

Merged
merged 2 commits into from
Sep 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -100,9 +100,12 @@ public int read(byte[] buffer, int offset, int len) throws IOException {
if (offset < 0 || len < 0 || (offset + len) > buffer.length) {
throw new IndexOutOfBoundsException("Offset="+offset+",len="+len+",buflen="+buffer.length);
}
if (len == 0 || position == contentLength) {
if (len == 0 ) {
return 0;
}
if (position == contentLength) {
return -1;
}

HttpURLConnection connection = null;
InputStream is = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,20 @@ public void testRandomRead() throws IOException {
assertEquals(buffer1, buffer2);
}

@Test
public void testReadExactlyOneByteAtEndOfFile() throws IOException {
try (final SeekableStream stream = new SeekableHTTPStream(new URL(BAM_URL_STRING))){
Copy link
Contributor

@pshapiro4broad pshapiro4broad Sep 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost, still missing the space between the ){. If you select the line and use the IDE's Reformat Code it will fix it for you.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

whoops, didn't see your comment until after I merged

byte[] buff = new byte[1];
long length = stream.length();
stream.seek(length - 1);
Assert.assertFalse(stream.eof());
Assert.assertEquals(stream.read(buff), 1);
Assert.assertTrue(stream.eof());
Assert.assertEquals(stream.read(buff), -1);
}
}


/**
* Test an attempt to read past the end of the file. The test file is 594,149 bytes in length. The test
* attempts to read a 1000 byte block starting at position 594000. A correct result would return 149 bytes.
Expand Down