Skip to content

Commit

Permalink
(#28) Added getBinaryStream with limitation
Browse files Browse the repository at this point in the history
  • Loading branch information
svettwer committed Apr 17, 2019
1 parent 97d3a81 commit be92434
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,13 @@ public void free() {

@Override
public InputStream getBinaryStream(final long pos, final long length) {
return null;
if(lobUtils.fitsInInt(pos) && lobUtils.fitsInInt(length)){
final int intPosWithOffset = (int) lobUtils.applyOffset(pos);
final int endIndex = intPosWithOffset + (int) length;
final byte[] subarray = ArrayUtils.subarray(content, intPosWithOffset, endIndex);
return new ByteArrayInputStream(subarray);
}
return new ByteArrayInputStream(ArrayUtils.EMPTY_BYTE_ARRAY);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,4 +161,18 @@ public void testPositionWithBlobPattern() throws SQLException {
//THEN
assertEquals(position, 6);
}

@Test
public void testGetLimitedBinaryStream() throws IOException {

//GIVEN
final byte[] expectedStreamContent = "Me Up".getBytes();
citrusBlob.setBytes(1, sampleBytes);

//WHEN
final InputStream limitedBinarySteam = citrusBlob.getBinaryStream(6, 5);

//THEN
assertEquals(IOUtils.toByteArray(limitedBinarySteam), expectedStreamContent);
}
}

0 comments on commit be92434

Please sign in to comment.