private void testInputStreamThrowsException(final boolean ioException) throws Exception {
Connection conn = getConnection("lob");
stat = conn.createStatement();
stat.execute("create table test(id identity, c clob, b blob)");
PreparedStatement prep = conn.prepareStatement("insert into test values(null, ?, ?)");
assertThrows(ErrorCode.IO_EXCEPTION_1, prep).
setCharacterStream(1, new Reader() {
int pos;
public int read(char[] buff, int off, int len) throws IOException {
pos += len;
if (pos > 100001) {
if (ioException) {
throw new IOException("");
}
throw new IllegalStateException();
}
return len;
}
public void close() throws IOException {
// nothing to do
}
}, -1);
prep.setString(1, new String(new char[10000]));
prep.setBytes(2, new byte[0]);
prep.execute();
prep.setString(1, "");
assertThrows(ErrorCode.IO_EXCEPTION_1, prep).
setBinaryStream(2, new InputStream() {
int pos;
public int read() throws IOException {
pos++;
if (pos > 100001) {
if (ioException) {
throw new IOException("");
}
throw new IllegalStateException();
}
return 0;
}
}, -1);
prep.setBytes(2, new byte[10000]);
prep.execute();
ResultSet rs = stat.executeQuery("select c, b from test order by id");
rs.next();
assertEquals(new String(new char[10000]), rs.getString(1));
assertEquals(new byte[0], rs.getBytes(2));
rs.next();