db-derby-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From krist...@apache.org
Subject svn commit: r675169 - /db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java
Date Wed, 09 Jul 2008 13:37:40 GMT
Author: kristwaa
Date: Wed Jul  9 06:37:39 2008
New Revision: 675169

URL: http://svn.apache.org/viewvc?rev=675169&view=rev
Log:
DERBY-3768: Make EmbedBlob.length use skip instead of read.
Replaced read loop with a skip loop (potential optimization).
Note the verification of EOF when skip returns zero, which seems safer (due to the somewhat
relaxed contract of InputStream.skip).
Patch file: derby-3768-1b-length_skip.diff

Modified:
    db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java

Modified: db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java
URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java?rev=675169&r1=675168&r2=675169&view=diff
==============================================================================
--- db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java (original)
+++ db/derby/code/trunk/java/engine/org/apache/derby/impl/jdbc/EmbedBlob.java Wed Jul  9 06:37:39
2008
@@ -25,18 +25,15 @@
 import org.apache.derby.iapi.reference.SQLState;
 import org.apache.derby.iapi.error.StandardException;
 import org.apache.derby.iapi.jdbc.EngineLOB;
-import org.apache.derby.iapi.services.monitor.Monitor;
+import org.apache.derby.iapi.reference.Limits;
 import org.apache.derby.iapi.services.sanity.SanityManager;
 import org.apache.derby.iapi.types.DataValueDescriptor;
 import org.apache.derby.iapi.types.Resetable;
-import org.apache.derby.iapi.services.io.NewByteArrayInputStream;
 import org.apache.derby.iapi.services.io.InputStreamUtil;
-import org.apache.derby.iapi.services.io.ArrayInputStream;
 
 import java.sql.SQLException;
 import java.sql.Blob;
 import java.io.InputStream;
-import java.io.EOFException;
 import java.io.IOException;
 
 /**
@@ -299,10 +296,19 @@
                 // Otherwise have to read the entire stream!
                 for (;;)
                 {
-                    int size = biStream.read(buf);
-                    if (size == -1)
-                        break;
-                    pos += size;
+                    long skipped = biStream.skip(Limits.DB2_LOB_MAXWIDTH);
+                    if (SanityManager.DEBUG) {
+                        SanityManager.ASSERT(skipped >= 0);
+                    }
+                    pos += skipped;
+                    // If skip reports zero bytes skipped, verify EOF.
+                    if (skipped == 0) {
+                        if (biStream.read() == -1) {
+                            break; // Exit the loop, no more data.
+                        } else {
+                            pos++;
+                        }
+                    }
                 }
                 // Save for future uses.
                 myLength = pos;



Mime
View raw message