use of org.apache.derby.iapi.services.io.DerbyIOException in project derby by apache.
the class SQLBinary method writeBlob.
/**
* Serialize a blob using the 8.1 encoding. Not called if null.
*
* @exception IOException io exception
*/
private void writeBlob(ObjectOutput out) throws IOException {
try {
int len = getBlobLength();
InputStream is = _blobValue.getBinaryStream();
writeLength(out, len);
int bytesRead = 0;
int numOfBytes = 0;
byte[] buffer = new byte[Math.min(len, LEN_OF_BUFFER_TO_WRITE_BLOB)];
while (bytesRead < len) {
numOfBytes = is.read(buffer);
if (numOfBytes == -1) {
throw new DerbyIOException(MessageService.getTextMessage(SQLState.SET_STREAM_INEXACT_LENGTH_DATA), SQLState.SET_STREAM_INEXACT_LENGTH_DATA);
}
out.write(buffer, 0, numOfBytes);
bytesRead += numOfBytes;
}
} catch (StandardException se) {
throw new IOException(se.getMessage());
} catch (SQLException se) {
throw new IOException(se.getMessage());
}
}
use of org.apache.derby.iapi.services.io.DerbyIOException in project derby by apache.
the class PreparedStatementTest method assertInternalDerbyIOExceptionState.
/**
* This methods is not to be used, but sometimes you have to!
*
* @param preSQLState the expected outer SQL state
* @param expectedInternal the expected internal SQL state
* @param sqle the outer SQLException
*/
private void assertInternalDerbyIOExceptionState(String preSQLState, String expectedInternal, SQLException sqle) {
assertSQLState("Outer/public SQL state incorrect", preSQLState, sqle);
// We need to dig a little with the current way exceptions are
// being reported. We can use getCause because we always run with
// Java SE 6 or later.
Throwable cause = getLastSQLException(sqle).getCause();
assertEquals("org.apache.derby.shared.common.error.StandardException", cause.getClass().getName());
cause = cause.getCause();
assertTrue("Exception not a DerbyIOException", cause instanceof DerbyIOException);
DerbyIOException dioe = (DerbyIOException) cause;
assertEquals("Incorrect internal SQL state", expectedInternal, dioe.getSQLState());
}
Aggregations