StandardBlob implements Blob { @Override public byte[] getBytes(final long posOrdinal, final int length) throws SQLException { assertNotFreed(); final int actualLength = Math.min(length, (int) len); if (posOrdinal < 1 || len - posOrdinal < 0 ) { throw newIllegalArgumentExceptionRange("posOrdinal", 1, len, posOrdinal); } final byte[] bytes = new byte[actualLength]; long pos = posOrdinal -1; for (int i = 0; i < actualLength; i++) { bytes[i] = buf[(int) pos]; pos++; } return bytes; } 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 getPartialBytes() throws SQLException { final int startIndex = 2; final int endIndex = BYTES.length - 4; byte[] expected = Arrays.copyOfRange(BYTES, startIndex, endIndex); byte[] actual = standardBlob.getBytes(startIndex + 1, endIndex - startIndex); assertArrayEquals(expected, actual); }