Thanks for the updated patch, Narayanan!
I looked at the javadoc for Blob.getBinaryStream(long,long) at http://java.sun.com/javase/6/docs/api/. It says
SQLException - if pos is less than 1 or if pos is greater than the number of bytes in the Blob or if pos + length is greater than the number of bytes in the Blob
(The wording is similar for Clob.getCharacterStream(long,long).)
I don't think that matches the current checks. For instance, Lob.checkPosition() throws exception if (pos > length() + 1) whereas the it should throw exception if (pos > length()) . And checkLength() only checks whether length is negative. It would probably be good to add tests for these boundary cases in BlobTest/ClobTest as well.
I don't think this part of getBinaryStream() is correct:
+ InputStream retVal = new java.io.ByteArrayInputStream
+ (binaryString_, (int)(pos), (int)length);
The pos argument starts on 1, whereas the offset argument to ByteArrayInputStream starts on 0. The tests in BlobTest passed, though, which I found a bit puzzling. It seems there is a dataOffset_ variable in Blob which, by accident, was one when running the tests, so the bug wasn't discovered. I believe pos should be replaced with (dataOffset_ + pos - 1).