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 2009/02/24 15:32:21 UTC
svn commit: r747393 - in /db/derby/code/branches/10.4/java:
engine/org/apache/derby/impl/jdbc/UpdatableBlobStream.java
testing/org/apache/derbyTesting/functionTests/tests/jdbc4/BlobTest.java
Author: kristwaa
Date: Tue Feb 24 14:32:20 2009
New Revision: 747393
URL: http://svn.apache.org/viewvc?rev=747393&view=rev
Log:
DERBY-4061: InputStream returned from Blob.getBinaryStream(long, long) terminates the stream by returning 0, should return -1.
Merged fix from trunk (revision 746236, derby-4061-1b.diff).
Modified:
db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/UpdatableBlobStream.java
db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/BlobTest.java
Modified: db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/UpdatableBlobStream.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/UpdatableBlobStream.java?rev=747393&r1=747392&r2=747393&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/UpdatableBlobStream.java (original)
+++ db/derby/code/branches/10.4/java/engine/org/apache/derby/impl/jdbc/UpdatableBlobStream.java Tue Feb 24 14:32:20 2009
@@ -190,7 +190,13 @@
*/
public int read(byte[] b, int off, int len) throws IOException {
updateIfRequired();
- int actualLength = (int) Math.min(len, maxPos - pos);
+ long remaining = maxPos - pos;
+ // Return EOF if the maximum allowed position has been reached,
+ // and we're trying to read at least one byte.
+ if (remaining == 0 && len > 0) {
+ return -1;
+ }
+ int actualLength = (int) Math.min(len, remaining);
int retValue = stream.read(b, off, actualLength);
if (retValue > 0)
pos += retValue;
@@ -217,12 +223,7 @@
* @see java.io.InputStream#read(byte[])
*/
public int read(byte[] b) throws IOException {
- updateIfRequired();
- int actualLength = (int) Math.min(b.length, maxPos - pos);
- int retValue = stream.read(b, 0, actualLength);
- if (retValue > 0)
- pos += retValue;
- return retValue;
+ return read(b, 0, b.length);
}
/**
Modified: db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/BlobTest.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/BlobTest.java?rev=747393&r1=747392&r2=747393&view=diff
==============================================================================
--- db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/BlobTest.java (original)
+++ db/derby/code/branches/10.4/java/testing/org/apache/derbyTesting/functionTests/tests/jdbc4/BlobTest.java Tue Feb 24 14:32:20 2009
@@ -519,6 +519,22 @@
}
}
+ /**
+ * Tests that draining a "sub-stream" from the Blob works.
+ * This is a repro for DERBY-4061, where we ended up with an infinite loop.
+ */
+ public void testGetBinaryStreamLongDrain()
+ throws IOException, SQLException {
+ initializeLongBlob(); // Ignoring id for now, use instance variable.
+ InputStream in = blob.getBinaryStream(2000, 5000);
+ byte[] buf = new byte[256];
+ while (in.read(buf, 0, buf.length) != -1) {
+ // This should end when we have read all the bytes in the stream.
+ // If the code hangs here, see DERBY-4061.
+ }
+ in.close();
+ blob.free();
+ }
/**
* Tests that the InputStream got from