int toRead = b.length;
// If the value given is null, return end of data
if (value == null) {
return -1;
}
if (value.isNull()) {
return -1;
}
// Calculate the number of bytes to return
int copyBytes = length - currentOffset;
// Is there more data to get?
if (copyBytes <= 0) {
return -1;
}
// Only copy up to the size of the given buffer
if (copyBytes > toRead) {
copyBytes = toRead;
}
// Get the data as a byte array
byte data[];
try {
data = value.getBytes();
}
catch (SQLException ex) {
return -1;
}
// Copy the data. The type of InputStream should be checked.
// We'll assume binary data for the SimpleText driver
System.arraycopy(data, currentOffset, b, 0, copyBytes);
// Increment our offset
currentOffset += copyBytes;
// Return the number of bytes copied
return copyBytes;