In ParameterWriter.write(OutputStream out, java.io.Reader reader, long length, boolean noBackslashEscapes)
The value returned from reader.read is the number of read characters not bytes. This value was used as input to writeBytesEscaped which expects the length in bytes.
Changed this to use the returned length in new String instead and using the length of the returned byte array as input to the writeBytesEscaped method. This should fix the setCharacterStream issue.
For the setClob issue, MySQLPreparedStatement.setClob used:
new StreamParameter(x.getAsciiStream(), ((MySQLBlob)x).length(), connection.noBackslashEscapes));
The length returned here is the length from MySQLClob.length() and not MySQLBlob.length (it doesn't help to cast to MySQLBlob) which again is the number of characters and not bytes. Fixed this by just removing the length parameter.
The change to MySQLBlob.getBinaryStream is to get a stream of the correct length and not padded to 1024 bytes.
The rest is just removing an unnecessary IOException and added test cases. And updated the ersion of surefire to allow running single tests like:
mvn test -Dtest=DriverTest#testClob3
I hope this explains the changes.