On 12/12/06, Oleg Khaschansky <[EMAIL PROTECTED]> wrote:

I experimented a bit with this test. It looks like RI is doing following:
if all the bytes from the pattern occured in the blob in the same
sequence as in the pattern (possibly with any other bytes between
them)


Is it reasonable?
Should Harmony follow RI's behaviour? Or just find the exact byte array in
blob data?
Could  jdbc/db gurus give some suggestions? Thanks a lot in adavance!

then it returns <the position where it found the last byte from
the pattern> - (<the pattern length> - 1).E.g. if the blob contents is
1,3,9,1,1,3,2,2,4,2,3,9,3,3 and the
pattern is 1,2,3 then it takes the position of the third occurence of
3 (after 1 and 2 occured) and subtracts 2 (the pattern length - 1)
from it. Then the return value is 9.

This behavior of RI seems to be undocumented and illogical.

On 12/12/06, Andrew Zhang <[EMAIL PROTECTED]> wrote:
> Hi folks,
>
> I found that RI's behaviour of SerialBlob.postion(byte[] pattern, long
> start) looks strange. Consider following code:
>
>     private void testPosition_BytePattern()
>             throws SerialException, SQLException {
>
>         byte[] buf = { 1, 2, 3, 4, 5, 6, 7, 8 };
>         SerialBlob blob = new SerialBlob(buf);
>
>
>         byte[]  pattern = new byte[] { 2, 4 };
>         long pos = blob.position(pattern, 1);
>         // FIXME: RI's bug?
>         assertEquals(-1, pos);
>
>     }
>
> It tries to find pattern "2,4" from blob with data "1,2,3,4,5,6,7,8". RI
> returns 3 instead of -1. Spec says the method "returns the position in
this
> SerialBlob object where the given pattern of bytes begins, starting the
> search at the specified position. "and "position numbering for the
return
> value starts at 1".
>
> Did I misunderstand the spec? Or it's a bug of RI? Thanks!
> --
> Best regards,
> Andrew Zhang
>
>




--
Best regards,
Andrew Zhang

Reply via email to