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 c6547df..dbb5489 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 @@ -37,7 +37,18 @@ public InputStream getBinaryStream() { @Override public long position(final byte[] pattern, final long start) { - return 0; + if(lobUtils.fitsInInt(start)){ + final int intStart = (int)start; + for(int position = intStart - 1; position < content.length; position++){ + if(content[position] == pattern[0]){ + final byte[] subarray = ArrayUtils.subarray(content, position, position + pattern.length); + if(Arrays.equals(subarray, pattern)){ + return (long) position + 1; + } + } + } + } + return -1; } @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 94e6753..3a6fc3a 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 @@ -130,4 +130,18 @@ public void testFree() throws IOException { final byte[] blobContent = IOUtils.toByteArray(binaryStream); assertEquals(blobContent, ArrayUtils.EMPTY_BYTE_ARRAY); } + + @Test + public void testPositionWithBytePattern() { + + //GIVEN + final byte[] pattern = "Me Up".getBytes(); + citrusBlob.setBytes(1, sampleBytes); + + //WHEN + final long position = citrusBlob.position(pattern, 1); + + //THEN + assertEquals(position, 6); + } } \ No newline at end of file