/**
* Tests the BlobOutputStream.write(byte b[], int off, int len) method
**/
public void testBlobWrite3Param() throws Exception {
InputStream streamIn = new LoopingAlphabetStream(streamSize[0]);
assertTrue("FAIL -- file not found", streamIn != null);
PreparedStatement stmt3 = prepareStatement(
"SELECT b FROM testBlobX1 WHERE a = 1");
ResultSet rs3 = stmt3.executeQuery();
rs3.next();
Blob blob = rs3.getBlob(1);
assertTrue ("FAIL -- blob is NULL", (blob != null));
int count = 0;
byte[] buffer = new byte[1024];
OutputStream outstream = blob.setBinaryStream(1L);
while ((count = streamIn.read(buffer)) != -1) {
outstream.write(buffer, 0, count);
}
outstream.close();
streamIn.close();
PreparedStatement stmt4 = prepareStatement(
"UPDATE testBlobX1 SET b = ? WHERE a = 1");
stmt4.setBlob(1, blob);
stmt4.executeUpdate();
stmt4.close();
rs3.close();
rs3 = stmt3.executeQuery();
assertTrue("FAIL -- blob not found", rs3.next());
blob = rs3.getBlob(1);
long new_length = blob.length();
assertEquals("FAIL -- wrong blob length;",
streamSize[0], new_length);
// Check contents ...
InputStream fStream = new LoopingAlphabetStream(streamSize[0]);
InputStream lStream = blob.getBinaryStream();
assertTrue("FAIL - Blob and file contents do not match",
compareLob2File(fStream, lStream));
fStream.close();
lStream.close();
rs3.close();
stmt3.close();
}