Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 24352 invoked from network); 4 Jul 2007 08:20:33 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 4 Jul 2007 08:20:33 -0000 Received: (qmail 68467 invoked by uid 500); 4 Jul 2007 08:20:36 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 68442 invoked by uid 500); 4 Jul 2007 08:20:36 -0000 Mailing-List: contact derby-commits-help@db.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: Reply-To: "Derby Development" List-Id: Delivered-To: mailing list derby-commits@db.apache.org Received: (qmail 68430 invoked by uid 99); 4 Jul 2007 08:20:36 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Jul 2007 01:20:36 -0700 X-ASF-Spam-Status: No, hits=-99.5 required=10.0 tests=ALL_TRUSTED,NO_REAL_NAME X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 04 Jul 2007 01:20:32 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 43DD71A981A; Wed, 4 Jul 2007 01:20:12 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r553121 - in /db/derby/code/branches/10.3/java/engine/org/apache/derby/impl/jdbc: ClobUpdatableReader.java UpdatableBlobStream.java Date: Wed, 04 Jul 2007 08:20:11 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070704082012.43DD71A981A@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 InputStream * 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;