? .settings
? blob-support.patch
? org/postgresql/test/jdbc3/Jdbc3BlobTest.java
Index: build.properties
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/build.properties,v
retrieving revision 1.6
diff -u -r1.6 build.properties
--- build.properties	2 Feb 2005 20:07:24 -0000	1.6
+++ build.properties	19 Feb 2005 17:45:45 -0000
@@ -8,3 +8,6 @@
 fullversion=8.1devel
 def_pgport=5432
 enable_debug=yes
+user=mike
+password=1gisu2t
+
Index: org/postgresql/jdbc2/AbstractJdbc2Blob.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc2/AbstractJdbc2Blob.java,v
retrieving revision 1.8
diff -u -r1.8 AbstractJdbc2Blob.java
--- org/postgresql/jdbc2/AbstractJdbc2Blob.java	15 Feb 2005 08:56:25 -0000	1.8
+++ org/postgresql/jdbc2/AbstractJdbc2Blob.java	19 Feb 2005 17:45:46 -0000
@@ -9,13 +9,15 @@
 */
 package org.postgresql.jdbc2;
 
-import org.postgresql.PGConnection;
-import org.postgresql.largeobject.LargeObject;
-import org.postgresql.largeobject.LargeObjectManager;
 import java.io.InputStream;
 import java.sql.Blob;
 import java.sql.SQLException;
 
+import org.postgresql.PGConnection;
+import org.postgresql.largeobject.LargeObject;
+import org.postgresql.largeobject.LargeObjectManager;
+import org.postgresql.util.GT;
+
 public abstract class AbstractJdbc2Blob
 {
     private LargeObject lo;
@@ -42,20 +44,131 @@
         return lo.read(length);
     }
 
-    /*
-     * For now, this is not implemented.
+    
+    
+    /**
+     * Iterate over the buffer looking for the specified pattern
+     * 
+     * @param pattern A pattern of bytes to search the blob for.
+     * @param start The position to start reading from.
      */
     public long position(byte[] pattern, long start) throws SQLException
     {
-        throw org.postgresql.Driver.notImplemented(this.getClass(), "position(byte[],long)");
+        assertPosition(start, pattern.length);
+        
+        int position = 0;
+        int patternIdx = 0;
+        long result = -1;
+        int tmpPosition = 0;
+        
+        for (LOIterator i = new LOIterator(start); i.hasNext(); position++)
+        {
+            byte b = i.next();
+            if (b == pattern[patternIdx])
+            {
+                if (patternIdx == 0)
+                {
+                    tmpPosition = position;                    
+                }
+                patternIdx++;
+                if (patternIdx == pattern.length)
+                {
+                    result = tmpPosition;
+                    break;
+                }
+            }
+            else
+            {
+                patternIdx = 0;
+            }
+        }
+        
+        return result;
+    }
+    
+    /**
+     * Iterates over a large object returning byte values.  Will buffer
+     * the data from the large object.
+     * 
+     *
+     */
+    private class LOIterator
+    {
+        private static final int BUFFER_SIZE = 8096;
+        private byte buffer[] = new byte[BUFFER_SIZE];
+        private int idx = BUFFER_SIZE;
+        private int numBytes = BUFFER_SIZE;
+        
+        public LOIterator(long start) throws SQLException
+        {
+            lo.seek((int) start);
+        }
+        
+        public boolean hasNext() throws SQLException
+        {
+            boolean result = false;
+            if (idx < numBytes)
+            {
+                result = true;
+            }
+            else
+            {
+                numBytes = lo.read(buffer, 0, BUFFER_SIZE);
+                idx = 0;
+                result = (numBytes > 0);
+            }
+            return result;
+        }
+        
+        private byte next()
+        {
+            return buffer[idx++];
+        }
     }
+    
 
-    /*
-     * This should be simply passing the byte value of the pattern Blob
+    /**
+     * This is simply passing the byte value of the pattern Blob
      */
     public long position(Blob pattern, long start) throws SQLException
     {
         return position(pattern.getBytes(0, (int)pattern.length()), start);
     }
 
+    /**
+     * Expose large object to derived classes.
+     * @return
+     */
+    protected LargeObject getLO()
+    {
+       return lo;
+    }
+    
+    /**
+     * Throws an exception if the pos value exceeds the max value by
+     * which the large object API can index.
+     * 
+     * @param pos Position to write at.
+     */
+    protected void assertPosition(long pos) throws SQLException
+    {
+        assertPosition(pos, 0);
+    }
+    
+    /**
+     * Throws an exception if the pos value exceeds the max value by
+     * which the large object API can index.
+     * 
+     * @param pos Position to write at.
+     * @param len number of bytes to write.
+     */
+    protected void assertPosition(long pos, long len) throws SQLException
+    {
+        if (pos + len > Integer.MAX_VALUE)
+        {
+            String err = GT.tr( "PostgreSQL Blobs can only index to: {0}", new Integer(Integer.MAX_VALUE));            
+            throw new SQLException(err);
+        }
+    }
+    
 }
Index: org/postgresql/jdbc3/AbstractJdbc3Blob.java
===================================================================
RCS file: /usr/local/cvsroot/pgjdbc/pgjdbc/org/postgresql/jdbc3/AbstractJdbc3Blob.java,v
retrieving revision 1.6
diff -u -r1.6 AbstractJdbc3Blob.java
--- org/postgresql/jdbc3/AbstractJdbc3Blob.java	15 Feb 2005 08:56:26 -0000	1.6
+++ org/postgresql/jdbc3/AbstractJdbc3Blob.java	19 Feb 2005 17:45:46 -0000
@@ -10,7 +10,9 @@
 package org.postgresql.jdbc3;
 
 
-import java.sql.*;
+import java.sql.SQLException;
+
+import org.postgresql.largeobject.LargeObject;
 
 public abstract class AbstractJdbc3Blob extends org.postgresql.jdbc2.AbstractJdbc2Blob
 {
@@ -37,10 +39,12 @@
      */
     public int setBytes(long pos, byte[] bytes) throws SQLException
     {
-        throw org.postgresql.Driver.notImplemented(this.getClass(), "setBytes(long,byte[]");
+        return setBytes(pos, bytes, 0, bytes.length);
     }
 
-    /**
+    
+
+   /**
      * Writes all or part of the given <code>byte</code> array to the
      * <code>BLOB</code> value that this <code>Blob</code> object represents
      * and returns the number of bytes written.
@@ -63,7 +67,11 @@
      */
     public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException
     {
-        throw org.postgresql.Driver.notImplemented(this.getClass(), "setBytes(long,byte[],int,int)");
+        assertPosition(pos);
+        LargeObject lo = getLO();
+        lo.seek((int) pos);
+        lo.write(bytes, offset, len);
+        return len;
     }
 
     /**
@@ -82,7 +90,10 @@
      */
     public java.io.OutputStream setBinaryStream(long pos) throws SQLException
     {
-        throw org.postgresql.Driver.notImplemented(this.getClass(), "setBinaryStream(long)");
+        assertPosition(pos);
+        LargeObject lo = getLO();
+        lo.seek((int) pos);
+        return lo.getOutputStream();
     }
 
     /**
