Search in sources :

Example 1 with DerbyIOException

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());
    }
}
Also used : StandardException(org.apache.derby.shared.common.error.StandardException) SQLException(java.sql.SQLException) FormatIdInputStream(org.apache.derby.iapi.services.io.FormatIdInputStream) InputStream(java.io.InputStream) DerbyIOException(org.apache.derby.iapi.services.io.DerbyIOException) IOException(java.io.IOException) DerbyIOException(org.apache.derby.iapi.services.io.DerbyIOException)

Example 2 with DerbyIOException

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());
}
Also used : DerbyIOException(org.apache.derby.iapi.services.io.DerbyIOException)

Aggregations

DerbyIOException (org.apache.derby.iapi.services.io.DerbyIOException)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 SQLException (java.sql.SQLException)1 FormatIdInputStream (org.apache.derby.iapi.services.io.FormatIdInputStream)1 StandardException (org.apache.derby.shared.common.error.StandardException)1