Skip to content

Commit

Permalink
(#28) Added position by byte pattern implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
svettwer committed Apr 15, 2019
1 parent 91a0054 commit 931a700
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 931a700

Please sign in to comment.