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:35:29 UTC

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

Author: kristwaa
Date: Thu Jun 24 09:35:29 2010
New Revision: 957473

URL: http://svn.apache.org/viewvc?rev=957473&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.5/   (props changed)
    db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLBinary.java

Propchange: db/derby/code/branches/10.5/
------------------------------------------------------------------------------
--- svn:mergeinfo (original)
+++ svn:mergeinfo Thu Jun 24 09:35:29 2010
@@ -1,2 +1,2 @@
 /db/derby/code/branches/10.6:957000
-/db/derby/code/trunk:769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,792434,793089,793588,794106,794303,794955,795166,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,829022,832379,833430,835286,881074,881444,882732,884163,887246,892912,897161,901165,901648,901760,903108,908418,911315,915733,916075,916897,918359,921028,927430,928065,942286,942476,942480,942587,946794,948045,948069,951346,955001,956075,956445,956659
+/db/derby/code/trunk:769596,769602,769606,769962,772090,772337,772449,772534,774281,777105,779681,782991,785131,785139,785163,785570,785662,788369,788670,788674,788968,789264,790218,792434,793089,793588,794106,794303,794955,795166,796020,796027,796316,796372,797147,798347,798742,800523,803548,803948,805696,808494,808850,809643,810860,812669,816531,816536,819006,822289,823659,824694,829022,832379,833430,835286,881074,881444,882732,884163,887246,892912,897161,901165,901648,901760,903108,908418,911315,915733,916075,916897,918359,921028,927430,928065,942286,942476,942480,942587,946794,948045,948069,951346,954748,955001,955634,956075,956445,956659

Modified: db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLBinary.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLBinary.java?rev=957473&r1=957472&r2=957473&view=diff
==============================================================================
--- db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLBinary.java (original)
+++ db/derby/code/branches/10.5/java/engine/org/apache/derby/iapi/types/SQLBinary.java Thu Jun 24 09:35:29 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) {
@@ -364,10 +367,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() ); }