// A length less stream that is capped, will return 0 even if there
// are more bytes in the application stream.
int remainingBytes = reader.clearLimit();
if (remainingBytes > 0 && valueLength > 0) {
// If we had a specified length, throw exception.
throw new DerbyIOException(
MessageService.getTextMessage(
SQLState.SET_STREAM_INEXACT_LENGTH_DATA),
SQLState.SET_STREAM_INEXACT_LENGTH_DATA);
}
// if we had a limit try reading one more character.
// JDBC 3.0 states the stream must have the correct number of
// characters in it.
if (remainingBytes == 0 && reader.read() >= 0) {
if (valueLength > -1) {
throw new DerbyIOException(
MessageService.getTextMessage(
SQLState.SET_STREAM_INEXACT_LENGTH_DATA),
SQLState.SET_STREAM_INEXACT_LENGTH_DATA);
} else {
// Stream was capped (length less) and too long.
// Try to truncate if allowed, or else throw exception.
if (canTruncate()) {
truncate();
} else {
throw new DerbyIOException(
MessageService.getTextMessage(
SQLState.LANG_STRING_TRUNCATION,
typeName,
"<stream-value>", // Don't show the whole value.
String.valueOf(Math.abs(valueLength))),