Return-Path: Delivered-To: apmail-db-derby-commits-archive@www.apache.org Received: (qmail 28618 invoked from network); 11 May 2007 21:11:34 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 11 May 2007 21:11:34 -0000 Received: (qmail 43871 invoked by uid 500); 11 May 2007 21:11:30 -0000 Delivered-To: apmail-db-derby-commits-archive@db.apache.org Received: (qmail 43818 invoked by uid 500); 11 May 2007 21:11:30 -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 43786 invoked by uid 99); 11 May 2007 21:11:30 -0000 Received: from herse.apache.org (HELO herse.apache.org) (140.211.11.133) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 11 May 2007 14:11:30 -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; Fri, 11 May 2007 14:11:23 -0700 Received: by eris.apache.org (Postfix, from userid 65534) id 03C911A9838; Fri, 11 May 2007 14:11:02 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r537291 - in /db/derby/code/trunk/java/client/org/apache/derby/client/am: ClobLocatorInputStream.java ClobLocatorOutputStream.java ClobLocatorReader.java ClobLocatorWriter.java Date: Fri, 11 May 2007 21:11:02 -0000 To: derby-commits@db.apache.org From: kahatlen@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070511211103.03C911A9838@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: kahatlen Date: Fri May 11 14:11:01 2007 New Revision: 537291 URL: http://svn.apache.org/viewvc?view=rev&rev=537291 Log: DERBY-2604: Implement Clob support for locators Follow-up patch which fixed problems with string encoding and boundary checking. Contributed by V. Narayanan. Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobLocatorInputStream.java db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobLocatorOutputStream.java db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobLocatorReader.java db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobLocatorWriter.java Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobLocatorInputStream.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobLocatorInputStream.java?view=diff&rev=537291&r1=537290&r2=537291 ============================================================================== --- db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobLocatorInputStream.java (original) +++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobLocatorInputStream.java Fri May 11 14:11:01 2007 @@ -49,12 +49,12 @@ /** * Connection used to read Clob from server. */ - private Connection connection; + private final Connection connection; /** * The Clob to be accessed. */ - private Clob clob; + private final Clob clob; /** * Current position in the underlying Clob. @@ -100,7 +100,7 @@ */ public int read(byte[] b, int off, int len) throws IOException { if (len == 0) return 0; - if ((off < 0) || (len < 0) || (off+len > b.length)) { + if ((off < 0) || (len < 0) || (len > b.length - off)) { throw new IndexOutOfBoundsException(); } @@ -129,7 +129,7 @@ String resultStr = connection.locatorProcedureCall(). clobGetSubString(clob.getLocator(), currentPos, actualLength); - byte[] result = resultStr.getBytes(); + byte[] result = getBytesFromString(resultStr); currentPos += result.length; return result; } catch (SqlException ex) { @@ -137,5 +137,48 @@ ioEx.initCause(ex); throw ioEx; } + } + + /** + * Returns a Byte array from the + * String passed as Input. + * + * @param str the input String. + * @return The Byte corresponding + * to the String that was + * input. + */ + private byte[] getBytesFromString(String str) { + //The Byte array that will hold the final + //converted Byte array that will be returned + //to the user + byte[] result = new byte[str.length()]; + + //Iterate through the String to + //Convert each character in the + //String + for (int i = 1; i <= str.length(); i++) { + //charAt function accpets a index that + //starts from 0 and ranges to length()-1 + char oneChar = str.charAt(i-1); + + if (oneChar <= 0xff) { + //Check if the value is lesser + //than maximum value that can + //be stored in a byte. If it is + //lesser store it directly in the + //byte array + result[i-1] = (byte)oneChar; + } + else { + //The value is greater than the + //maximum value that can be + //stored. Use the value 0x003f + //which corresponds to '?' + //signifying an unknown character + result[i-1] = 0x3f; + } + } + return result; } } Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobLocatorOutputStream.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobLocatorOutputStream.java?view=diff&rev=537291&r1=537290&r2=537291 ============================================================================== --- db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobLocatorOutputStream.java (original) +++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobLocatorOutputStream.java Fri May 11 14:11:01 2007 @@ -40,12 +40,12 @@ /** * Connection used to read Clob from server. */ - private Connection connection; + private final Connection connection; /** * The Clob to be accessed. */ - private Clob clob; + private final Clob clob; /** * Current position in the underlying Clob. @@ -101,7 +101,7 @@ public void write(byte[] b, int off, int len) throws IOException { if (len == 0) return; if ((off < 0) || (off > b.length) || (len < 0) || - (off+len > b.length) || (off+len < 0)) { + (len > b.length - off)) { throw new IndexOutOfBoundsException(); } @@ -132,7 +132,7 @@ */ private void writeBytes(byte[] b) throws IOException { try { - String clobStr = new String(b); + String clobStr = new String(b, "ISO-8859-1"); connection.locatorProcedureCall().clobSetString (clob.locator_, currentPos, b.length, clobStr); currentPos += b.length; Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobLocatorReader.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobLocatorReader.java?view=diff&rev=537291&r1=537290&r2=537291 ============================================================================== --- db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobLocatorReader.java (original) +++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobLocatorReader.java Fri May 11 14:11:01 2007 @@ -40,12 +40,12 @@ /** * Connection used to read Clob from server. */ - private Connection connection; + private final Connection connection; /** * The Clob to be accessed. */ - private Clob clob; + private final Clob clob; /** * Current position in the underlying Clob. @@ -124,7 +124,7 @@ public int read(char[] c, int off, int len) throws IOException { checkClosed(); if (len == 0) return 0; - if ((off < 0) || (len < 0) || (off+len > c.length)) { + if ((off < 0) || (len < 0) || (len > c.length - off)) { throw new IndexOutOfBoundsException(); } @@ -145,8 +145,6 @@ return; } isClosed = true; - connection = null; - clob = null; } /** Modified: db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobLocatorWriter.java URL: http://svn.apache.org/viewvc/db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobLocatorWriter.java?view=diff&rev=537291&r1=537290&r2=537291 ============================================================================== --- db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobLocatorWriter.java (original) +++ db/derby/code/trunk/java/client/org/apache/derby/client/am/ClobLocatorWriter.java Fri May 11 14:11:01 2007 @@ -35,12 +35,12 @@ /** * Connection used to read Clob from server. */ - private Connection connection; + private final Connection connection; /** * The Clob to be accessed. */ - private Clob clob; + private final Clob clob; /** * Current position in the underlying Clob. @@ -86,8 +86,6 @@ return; } isClosed = true; - connection = null; - clob = null; } /** @@ -147,7 +145,7 @@ checkClosed(); if (len == 0) return; if ((off < 0) || (off > c.length) || (len < 0) || - (off+len > c.length) || (off+len < 0)) { + (len > c.length - off)) { throw new IndexOutOfBoundsException(); } writeCharacters(c, off, len);