From be92434322c44ec453ff7eb3c6a50e05271f41e2 Mon Sep 17 00:00:00 2001 From: Sven Hettwer Date: Wed, 17 Apr 2019 09:23:07 +0200 Subject: [PATCH] (citrusframework/citrus-db#28) Added getBinaryStream with limitation --- .../consol/citrus/db/driver/data/CitrusBlob.java | 8 +++++++- .../citrus/db/driver/data/CitrusBlobTest.java | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/driver/src/main/java/com/consol/citrus/db/driver/data/CitrusBlob.java b/driver/src/main/java/com/consol/citrus/db/driver/data/CitrusBlob.java index 31901f6..3502839 100644 --- a/driver/src/main/java/com/consol/citrus/db/driver/data/CitrusBlob.java +++ b/driver/src/main/java/com/consol/citrus/db/driver/data/CitrusBlob.java @@ -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 diff --git a/driver/src/test/java/com/consol/citrus/db/driver/data/CitrusBlobTest.java b/driver/src/test/java/com/consol/citrus/db/driver/data/CitrusBlobTest.java index f31589a..427dfd0 100644 --- a/driver/src/test/java/com/consol/citrus/db/driver/data/CitrusBlobTest.java +++ b/driver/src/test/java/com/consol/citrus/db/driver/data/CitrusBlobTest.java @@ -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); + } } \ No newline at end of file