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 ka...@apache.org on 2007/07/04 10:20:11 UTC
svn commit: r553121 - in
/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc:
ClobUpdatableReader.java UpdatableBlobStream.java
Author: kahatlen
Date: Wed Jul 4 01:20:01 2007
New Revision: 553121
URL: http://svn.apache.org/viewvc?view=rev&rev=553121
Log:
DERBY-2890: Simplify handling of maxPos in UpdatableBlobStream and
ClobUpdatableReader
Merged from trunk (revision 552702).
Modified:
db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/ClobUpdatableReader.java
db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/UpdatableBlobStream.java
Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/ClobUpdatableReader.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/ClobUpdatableReader.java?view=diff&rev=553121&r1=553120&r2=553121
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/ClobUpdatableReader.java (original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/ClobUpdatableReader.java Wed Jul 4 01:20:01 2007
@@ -56,7 +56,7 @@
/** clob object this object is associated */
private final EmbedClob clob;
/**
- * Position in Clob where to stop reading.
+ * Position in Clob where to stop reading unless EOF is reached first.
*/
private final long maxPos;
@@ -74,8 +74,8 @@
this.conChild = conChild;
this.stream = stream;
//The subset of the Clob has not been requested.
- //Hence set maxPos to -1.
- this.maxPos = -1;
+ //Hence set maxPos to infinity (or as close as we get).
+ this.maxPos = Long.MAX_VALUE;
init (stream, 0);
}
@@ -90,8 +90,8 @@
this.clob = clob;
this.conChild = clob;
// A subset of the Clob has not been requested.
- // Hence set maxPos to -1.
- this.maxPos = -1;
+ // Hence set maxPos to infinity (or as close as we get).
+ this.maxPos = Long.MAX_VALUE;
InternalClob internalClob = clob.getInternalClob();
materialized = internalClob.isWritable();
@@ -165,24 +165,13 @@
public int read(char[] cbuf, int off, int len) throws IOException {
updateIfRequired();
- //If maxPos is not invalid and the current position inside the
- //stream has exceeded maxPos the read sould return -1 signifying
- //end of stream.
- if (maxPos != -1 && pos >= maxPos) {
+ //If the stream has exceeded maxPos the read should return -1
+ //signifying end of stream.
+ if (pos >= maxPos) {
return -1;
}
- int actualLength = 0;
- //If maxPos is not invalid then ensure that the length(len)
- //that is requested falls within the restriction set by maxPos.
- if(maxPos != -1) {
- actualLength
- = (int )Math.min(len, maxPos - pos);
- }
- else {
- //maxPos has not been set. Make maxPos the length requested.
- actualLength = len;
- }
+ int actualLength = (int) Math.min(len, maxPos - pos);
int ret = streamReader.read (cbuf, off, actualLength);
if (ret >= 0) {
pos += ret;
Modified: db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/UpdatableBlobStream.java
URL: http://svn.apache.org/viewvc/db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/UpdatableBlobStream.java?view=diff&rev=553121&r1=553120&r2=553121
==============================================================================
--- db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/UpdatableBlobStream.java (original)
+++ db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc/UpdatableBlobStream.java Wed Jul 4 01:20:01 2007
@@ -49,9 +49,9 @@
private final EmbedBlob blob;
/**
- * Position in Blob where to stop reading.
+ * Position in Blob where to stop reading unless EOF is reached first.
*/
- private long maxPos;
+ private final long maxPos;
/**
@@ -60,15 +60,13 @@
*
* @param blob EmbedBlob this stream is associated with.
* @param is InputStream this class is going to use internally.
+ * @throws IOException if an I/O error occurs
*/
- UpdatableBlobStream (EmbedBlob blob, InputStream is) {
- stream = is;
- this.pos = 0;
- this.blob = blob;
- //The subset of the Blob
- //has not been requested.
- //Hence set maxPos to -1.
- this.maxPos = -1;
+ UpdatableBlobStream (EmbedBlob blob, InputStream is)
+ throws IOException {
+ // The entire Blob has been requested, hence set length to infinity (or
+ // as close as we get).
+ this(blob, is, 0L, Long.MAX_VALUE);
}
/**
@@ -83,20 +81,18 @@
* @param len The length to which the underlying <code>InputStream</code>
* has to be restricted.
* @throws IOException
- * @throws SQLException
*/
UpdatableBlobStream (EmbedBlob blob, InputStream is, long pos, long len)
- throws IOException, SQLException {
- this(blob, is);
- //The length requested cannot exceed the length
- //of the underlying Blob object. Hence chose the
- //minimum of the length of the underlying Blob
- //object and requested length.
- maxPos = Math.min(blob.length(), pos + len);
+ throws IOException {
+ this.blob = blob;
+ stream = is;
+ maxPos = pos + len;
//Skip to the requested position
//inside the stream.
- skip(pos);
+ if (pos > 0) {
+ skip(pos);
+ }
}
/**
@@ -158,11 +154,9 @@
public int read() throws IOException {
updateIfRequired();
- //If maxPos is not invalid and the current
- //position inside the stream has exceeded
- //maxPos the read sould return -1 signifying
- //end of stream.
- if (maxPos != -1 && pos >= maxPos) {
+ //If the current position inside the stream has exceeded maxPos, the
+ //read should return -1 signifying end of stream.
+ if (pos >= maxPos) {
return -1;
}
int ret = stream.read();
@@ -197,22 +191,8 @@
* @see java.io.InputStream#read(byte[],int,int)
*/
public int read(byte[] b, int off, int len) throws IOException {
- int actualLength = 0;
updateIfRequired();
-
- //If maxPos is not invalid then
- //ensure that the length(len)
- //that is requested falls within
- //the restriction set by maxPos.
- if(maxPos != -1) {
- actualLength
- = (int )Math.min(len, maxPos - pos);
- }
- else {
- //maxPos has not been set. Make
- //maxPos the length requested.
- actualLength = len;
- }
+ int actualLength = (int) Math.min(len, maxPos - pos);
int retValue = stream.read(b, off, actualLength);
if (retValue > 0)
pos += retValue;
@@ -240,21 +220,7 @@
*/
public int read(byte[] b) throws IOException {
updateIfRequired();
- int actualLength = 0;
- //If maxPos is not invalid
- //then ensure that the length
- //(len of the byte array b)
- //falls within the restriction
- //set by maxPos.
- if(maxPos != -1) {
- actualLength
- = (int )Math.min(b.length, maxPos - pos);
- }
- else {
- //maxPos has not been set. Make
- //maxPos the length requested.
- actualLength = b.length;
- }
+ int actualLength = (int) Math.min(b.length, maxPos - pos);
int retValue = stream.read(b, 0, actualLength);
if (retValue > 0)
pos += retValue;