=== modified file 'pom.xml'
--- old/pom.xml	2013-02-28 22:48:27 +0000
+++ new/pom.xml	2013-03-21 11:26:53 +0000
@@ -52,7 +52,7 @@
             <plugin>
                 <groupId>org.apache.maven.plugins</groupId>
                 <artifactId>maven-surefire-plugin</artifactId>
-                <version>2.4.2</version>
+                <version>2.12.4</version>
             </plugin>
             <plugin>
                   <groupId>org.apache.maven.plugins</groupId>

=== modified file 'src/main/java/org/mariadb/jdbc/MySQLBlob.java'
--- old/src/main/java/org/mariadb/jdbc/MySQLBlob.java	2012-12-21 18:15:36 +0000
+++ new/src/main/java/org/mariadb/jdbc/MySQLBlob.java	2013-03-21 13:05:02 +0000
@@ -147,7 +147,7 @@
      * @see #setBinaryStream
      */
     public InputStream getBinaryStream() throws SQLException {
-        return new ByteArrayInputStream(this.blobContent);
+      return new ByteArrayInputStream(this.blobContent, 0, actualSize);
     }
 
     /**
@@ -406,4 +406,4 @@
     public void write(byte[] buf) {
         write(buf, 0, buf.length);
     }
-}
\ No newline at end of file
+}

=== modified file 'src/main/java/org/mariadb/jdbc/MySQLPreparedStatement.java'
--- old/src/main/java/org/mariadb/jdbc/MySQLPreparedStatement.java	2013-02-18 14:20:40 +0000
+++ new/src/main/java/org/mariadb/jdbc/MySQLPreparedStatement.java	2013-03-21 12:41:21 +0000
@@ -279,7 +279,7 @@
             return;
         }
         setParameter(parameterIndex,
-                new StreamParameter(x.getAsciiStream(), ((MySQLBlob)x).length(), connection.noBackslashEscapes));
+                new StreamParameter(x.getAsciiStream(), connection.noBackslashEscapes));
     }
 
     /**
@@ -826,12 +826,7 @@
             setNull(parameterIndex, Types.BLOB);
             return;
         }
-
-        try {
-            setParameter(parameterIndex, new StreamParameter(x, connection.noBackslashEscapes));
-        } catch (IOException e) {
-            throw SQLExceptionMapper.getSQLException("Could not read stream");
-        }
+        setParameter(parameterIndex, new StreamParameter(x, connection.noBackslashEscapes));
     }
 
     /**
@@ -860,12 +855,7 @@
             setNull(parameterIndex, Types.BLOB);
             return;
         }
-
-        try {
-                setParameter(parameterIndex, new StreamParameter(x, connection.noBackslashEscapes));
-        } catch (IOException e) {
-            throw SQLExceptionMapper.getSQLException("Could not read stream");
-        }
+        setParameter(parameterIndex, new StreamParameter(x, connection.noBackslashEscapes));
     }
 
     /**
@@ -967,15 +957,7 @@
             setNull(parameterIndex, Types.BLOB);
             return;
         }
-
-
-        try {
-                setParameter(parameterIndex, new StreamParameter(inputStream, connection.noBackslashEscapes));
-        } catch (IOException e) {
-            throw SQLExceptionMapper.getSQLException("Could not read stream");
-        }
-
-
+        setParameter(parameterIndex, new StreamParameter(inputStream, connection.noBackslashEscapes));
     }
 
     /**

=== modified file 'src/main/java/org/mariadb/jdbc/internal/common/query/parameters/ParameterWriter.java'
--- old/src/main/java/org/mariadb/jdbc/internal/common/query/parameters/ParameterWriter.java	2012-11-27 17:47:27 +0000
+++ new/src/main/java/org/mariadb/jdbc/internal/common/query/parameters/ParameterWriter.java	2013-03-21 13:05:23 +0000
@@ -80,7 +80,6 @@
         byte[] buffer = new byte[1024];
         long bytesLeft = length;
         int len;
-
         for (;;) {
             int bytesToRead = (int)Math.min(bytesLeft, buffer.length);
             if(bytesToRead == 0)
@@ -118,7 +117,8 @@
             len = reader.read(buffer,0, charsToRead);
             if (len <= 0)
                 break;
-            writeBytesEscaped(out, new String(buffer).getBytes(UTF8), len, noBackslashEscapes);
+            byte[] bytes = new String(buffer, 0, len).getBytes(UTF8);
+            writeBytesEscaped(out, bytes, bytes.length, noBackslashEscapes);
             charsLeft -= len;
         }
         out.write(QUOTE);

=== modified file 'src/main/java/org/mariadb/jdbc/internal/common/query/parameters/StreamParameter.java'
--- old/src/main/java/org/mariadb/jdbc/internal/common/query/parameters/StreamParameter.java	2012-12-21 18:15:36 +0000
+++ new/src/main/java/org/mariadb/jdbc/internal/common/query/parameters/StreamParameter.java	2013-03-21 12:33:49 +0000
@@ -64,7 +64,7 @@
         this.length = length;
         this.noBackslashEscapes = noBackslashEscapes;
     }
-    public StreamParameter(InputStream is, boolean noBackSlashEscapes) throws IOException {
+    public StreamParameter(InputStream is, boolean noBackSlashEscapes) {
         this(is,Long.MAX_VALUE, noBackSlashEscapes);
     }
 
@@ -74,4 +74,4 @@
         else
             ParameterWriter.write(os, is, length, noBackslashEscapes);
     }
-}
\ No newline at end of file
+}

=== modified file 'src/test/java/org/mariadb/jdbc/DriverTest.java'
--- old/src/test/java/org/mariadb/jdbc/DriverTest.java	2013-02-18 14:21:03 +0000
+++ new/src/test/java/org/mariadb/jdbc/DriverTest.java	2013-03-21 12:37:35 +0000
@@ -533,8 +533,9 @@
         while((ch = is.read()) != -1) {
             sb.append((char)ch);
         }
-        assertEquals(sb.toString(),(toInsert));
+        assertEquals((toInsert), sb.toString());
     }
+
     @Test
     public void testCharacterStreamWithLength() throws SQLException, IOException {
         connection.createStatement().execute("drop table if exists streamtest2");
@@ -553,7 +554,49 @@
         while((ch = rdr.read()) != -1) {
             sb.append((char)ch);
         }
-        assertEquals(sb.toString(),toInsert.substring(0,5));
+        assertEquals(toInsert.substring(0,5), sb.toString());
+    }
+
+    @Test
+    public void testCharacterStreamWithMultibyteCharacterAndLength() throws SQLException, IOException {
+        connection.createStatement().execute("drop table if exists streamtest2");
+        connection.createStatement().execute("create table streamtest2 (id int primary key not null, strm text)");
+        PreparedStatement stmt = connection.prepareStatement("insert into streamtest2 (id, strm) values (?,?)");
+        stmt.setInt(1,2);
+        String toInsert = "\u00D8abcdefgh\njklmn\"";
+        Reader reader = new StringReader(toInsert);
+        stmt.setCharacterStream(2, reader, 5);
+        stmt.execute();
+        ResultSet rs = connection.createStatement().executeQuery("select * from streamtest2");
+        rs.next();
+        Reader rdr = rs.getCharacterStream("strm");
+        StringBuilder sb = new StringBuilder();
+        int ch;
+        while((ch = rdr.read()) != -1) {
+            sb.append((char)ch);
+        }
+        assertEquals(toInsert.substring(0,5), sb.toString());
+    }
+
+    @Test
+    public void testCharacterStreamWithMultibyteCharacter() throws SQLException, IOException {
+        connection.createStatement().execute("drop table if exists streamtest2");
+        connection.createStatement().execute("create table streamtest2 (id int primary key not null, strm text)");
+        PreparedStatement stmt = connection.prepareStatement("insert into streamtest2 (id, strm) values (?,?)");
+        stmt.setInt(1,2);
+        String toInsert = "\u00D8abcdefgh\njklmn\"";
+        Reader reader = new StringReader(toInsert);
+        stmt.setCharacterStream(2, reader);
+        stmt.execute();
+        ResultSet rs = connection.createStatement().executeQuery("select * from streamtest2");
+        rs.next();
+        Reader rdr = rs.getCharacterStream("strm");
+        StringBuilder sb = new StringBuilder();
+        int ch;
+        while((ch = rdr.read()) != -1) {
+            sb.append((char)ch);
+        }
+        assertEquals(toInsert, sb.toString());
     }
 
     @Test
@@ -619,6 +662,23 @@
     }
 
     @Test
+    public void testClobWithLengthAndMultibyteCharacter() throws SQLException, IOException {
+        connection.createStatement().execute("drop table if exists clobtest");
+        connection.createStatement().execute("create table clobtest (id int not null primary key, strm text)");
+        PreparedStatement stmt = connection.prepareStatement("insert into clobtest (id, strm) values (?,?)");
+        String clob = "\u00D8clob";
+        stmt.setInt(1,1);
+        stmt.setClob(2, new StringReader(clob));
+        stmt.execute();
+        ResultSet rs = connection.createStatement().executeQuery("select * from clobtest");
+        rs.next();
+        Reader readStuff = rs.getClob("strm").getCharacterStream();
+        char[] a = new char[5];
+        readStuff.read(a);
+        Assert.assertEquals(new String(a), clob);
+    }
+
+    @Test
     public void  testClob2() throws SQLException, IOException {
         connection.createStatement().execute("drop table if exists clobtest");
         connection.createStatement().execute("create table clobtest (id int not null primary key, strm text)");
@@ -635,7 +695,26 @@
         Object o = rs.getObject(2);
         assertTrue(o instanceof String);
         String s = rs.getString(2);
-        assertTrue(s.equals("hello"));
+        assertEquals("hello", s);
+    }
+    @Test
+    public void  testClob3() throws SQLException, IOException {
+        connection.createStatement().execute("drop table if exists clobtest");
+        connection.createStatement().execute("create table clobtest (id int not null primary key, strm text)");
+        PreparedStatement stmt = connection.prepareStatement("insert into clobtest (id, strm) values (?,?)");
+        Clob clob = connection.createClob();
+        Writer writer = clob.setCharacterStream(1);
+        writer.write("\u00D8hello", 0, 6);
+        writer.flush();
+        stmt.setInt(1,1);
+        stmt.setClob(2,clob);
+        stmt.execute();
+        ResultSet rs = connection.createStatement().executeQuery("select * from clobtest");
+        rs.next();
+        Object o = rs.getObject(2);
+        assertTrue(o instanceof String);
+        String s = rs.getString(2);
+        assertEquals("\u00D8hello", s);
     }
     @Test
     public void testEmptyResultSet() throws SQLException {
@@ -1541,4 +1620,4 @@
         conn.close();  
 
     }
-}
\ No newline at end of file
+}

