harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ton...@apache.org
Subject svn commit: r549733 - in /harmony/enhanced/classlib/branches/java6/modules/sql/src: main/java/java/sql/Blob.java main/java/javax/sql/rowset/serial/SerialBlob.java test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialBlobTest.java
Date Fri, 22 Jun 2007 06:28:22 GMT
Author: tonywu
Date: Thu Jun 21 23:28:21 2007
New Revision: 549733

URL: http://svn.apache.org/viewvc?view=rev&rev=549733
Log:
new method in interface java.sql.Blob:  public free()V and public getBinaryStream(JJ)Ljava/io/InputStream

Modified:
    harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/Blob.java
    harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/javax/sql/rowset/serial/SerialBlob.java
    harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialBlobTest.java

Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/Blob.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/Blob.java?view=diff&rev=549733&r1=549732&r2=549733
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/Blob.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/java/sql/Blob.java
Thu Jun 21 23:28:21 2007
@@ -157,4 +157,18 @@
      *             if an error occurs accessing the Blob
      */
     public void truncate(long len) throws SQLException;
+    
+    /**
+     * TODO Javadoc
+     * 
+     * @throws SQLException
+     */
+    public void free() throws SQLException;
+
+    /**
+     * TODO Javadoc
+     * 
+     * @throws SQLException
+     */
+    public InputStream getBinaryStream(long pos, long length) throws SQLException;
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/javax/sql/rowset/serial/SerialBlob.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/javax/sql/rowset/serial/SerialBlob.java?view=diff&rev=549733&r1=549732&r2=549733
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/javax/sql/rowset/serial/SerialBlob.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/main/java/javax/sql/rowset/serial/SerialBlob.java
Thu Jun 21 23:28:21 2007
@@ -23,6 +23,7 @@
 import java.io.Serializable;
 import java.sql.Blob;
 import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
 
 import org.apache.harmony.sql.internal.nls.Messages;
 
@@ -233,4 +234,18 @@
         len = length;
     }
 
+    public void free() throws SQLException {
+        throw new SQLFeatureNotSupportedException();
+    }
+
+    public InputStream getBinaryStream(long pos, long length)
+            throws SQLException {
+        if (len == -1) {
+            throw new SerialException(Messages.getString("sql.38"));
+        }
+        if (pos < 1 || pos + length > len) {
+            throw new SerialException(Messages.getString("sql.22"));
+        }
+        return new ByteArrayInputStream(buf, (int) pos, (int) length);
+    }
 }

Modified: harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialBlobTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialBlobTest.java?view=diff&rev=549733&r1=549732&r2=549733
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialBlobTest.java
(original)
+++ harmony/enhanced/classlib/branches/java6/modules/sql/src/test/java/org/apache/harmony/sql/tests/javax/sql/rowset/serial/SerialBlobTest.java
Thu Jun 21 23:28:21 2007
@@ -22,6 +22,7 @@
 import java.io.OutputStream;
 import java.sql.Blob;
 import java.sql.SQLException;
+import java.sql.SQLFeatureNotSupportedException;
 import java.util.Arrays;
 
 import javax.sql.rowset.serial.SerialBlob;
@@ -349,6 +350,53 @@
             // expected
         }
     }
+    
+    public void test_free() throws Exception {
+        MockSerialBlob mockBlob = new MockSerialBlob();
+        mockBlob.binaryStream = new ByteArrayOutputStream();
+        SerialBlob serialBlob = new SerialBlob(mockBlob);
+        try {
+            serialBlob.free();
+            fail("should throw SQLFeatureNotSupportedException");
+        } catch (SQLFeatureNotSupportedException e) {
+            // expected
+        }
+    }
+    
+    public void testGetBinaryStreamJJ() throws Exception {
+        byte[] buf = { 1, 2, 3, 4, 5, 6, 7, 8 };
+        SerialBlob serialBlob = new SerialBlob(buf);
+        try{
+            serialBlob.getBinaryStream(0,4);
+            fail("Should throw SQLException");
+        }catch(SQLException e){
+            // expected
+        }
+        try{
+            serialBlob.getBinaryStream(3,8);
+            fail("Should throw SQLException");
+        }catch(SQLException e){
+            // expected
+        }
+        
+        
+        InputStream is = serialBlob.getBinaryStream(2,4);
+        int i = 0;
+        while (true) {
+            int b = is.read();
+            if (b == -1) {
+                if (i < 4) {
+                    fail("returned input stream contains too few data");
+                }
+                break;
+            }
+
+            if (i > 4) {
+                fail("returned input stream contains too much data");
+            }
+            assertEquals(buf[2+i++], b);
+        }
+    }
 
     private void assertBlobPosition_BytePattern(Blob blob)
             throws SerialException, SQLException {
@@ -527,6 +575,14 @@
 
         public void truncate(long len) throws SQLException {
 
+        }
+
+        public void free() throws SQLException {
+            
+        }
+
+        public InputStream getBinaryStream(long pos, long length) throws SQLException {
+            return null;
         }
 
     }



Mime
View raw message