StandardBlob implements Blob { @Override public long position(byte[] pattern, long startOrdinal) { assertNotFreed(); if (startOrdinal < 1 || startOrdinal > len) { return -1; } final long patternLength = pattern.length; int pos = (int) startOrdinal - 1; int i = 0; while (pos < len) { if (pattern[i] == buf[pos]) { if (i + 1 == patternLength) { return (pos + 1) - (patternLength - 1); } i++; pos++; } else if (pattern[i] != buf[pos]) { pos++; } } return -1; } StandardBlob(byte[] buf); @Override long length(); @Override byte[] getBytes(final long posOrdinal, final int length); @Override InputStream getBinaryStream(); @Override long position(byte[] pattern, long startOrdinal); @Override long position(Blob pattern, long start); @Override int setBytes(long pos, byte[] bytes); @Override int setBytes(long posOrdinal, byte[] bytes, int offset, int length); @Override OutputStream setBinaryStream(long pos); @Override void truncate(long length); @Override void free(); @Override InputStream getBinaryStream(long pos, long length);  }
@Test void getBlobStartPosition() throws SQLException { assertEquals(1, standardBlob.position(standardBlob, 1)); }
@Test void getSliceStartPosition() throws SQLException { final int startIndex = 2; final int endIndex = BYTES.length - 4; byte[] arraySlice = Arrays.copyOfRange(BYTES, startIndex, endIndex); long sliceStartIndex = standardBlob.position(arraySlice, 1); assertEquals(startIndex, sliceStartIndex - 1); }