You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-commits@db.apache.org by kr...@apache.org on 2010/06/24 11:34:38 UTC

svn commit: r957472 - in /db/derby/code/branches/10.6: ./ java/engine/org/apache/derby/iapi/types/SQLBinary.java

Author: kristwaa
Date: Thu Jun 24 09:34:38 2010
New Revision: 957472

URL: http://svn.apache.org/viewvc?rev=957472&view=rev
Log:
DERBY-4686: SQLBinary.writeBlob is inefficient, reading one byte at a time from the source BLOB

Merged fix from trunk (revisions 954748 and 955634).

Modified:
    db/derby/code/branches/10.6/   (props changed)
    db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/types/SQLBinary.java

Propchange: db/derby/code/branches/10.6/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jun 24 09:34:38 2010
@@ -1,2 +1,2 @@
-/db/derby/code/trunk:938547,938796,938959,939231,940462,940469,941627,942031,942286,942476,942480,942587,944152,946794,948045,948069,951346,952138,952237,954344,954421,954544,955001,956075,956234,956445,956659,957260
+/db/derby/code/trunk:938547,938796,938959,939231,940462,940469,941627,942031,942286,942476,942480,942587,944152,946794,948045,948069,951346,952138,952237,954344,954421,954544,954748,955001,955634,956075,956234,956445,956659,957260
 /db/derby/docs/trunk:954344

Modified: db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/types/SQLBinary.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/types/SQLBinary.java?rev=957472&r1=957471&r2=957472&view=diff
==============================================================================
--- db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/types/SQLBinary.java (original)
+++ db/derby/code/branches/10.6/java/engine/org/apache/derby/iapi/types/SQLBinary.java Thu Jun 24 09:34:38 2010
@@ -31,6 +31,7 @@ import org.apache.derby.iapi.types.DataV
 import org.apache.derby.iapi.types.ConcatableDataValue;
 import org.apache.derby.iapi.error.StandardException;
 
+import org.apache.derby.iapi.services.io.DerbyIOException;
 import org.apache.derby.iapi.services.io.StoredFormatIds;
 import org.apache.derby.iapi.services.io.FormatIdInputStream;
 
@@ -101,6 +102,8 @@ abstract class SQLBinary
 
     private static final int BASE_MEMORY_USAGE = ClassSize.estimateBaseFromCatalog( SQLBinary.class);
 
+    private static final int LEN_OF_BUFFER_TO_WRITE_BLOB = 1024;
+
     public int estimateMemoryUsage()
     {
         if (dataValue == null) {
@@ -368,10 +371,23 @@ abstract class SQLBinary
             InputStream         is = _blobValue.getBinaryStream();
             
             writeLength( out, len );
-
-            for ( int i = 0; i < len; i++ )
-            {
-                out.write( is.read() );
+            
+            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() ); }