OSDN Git Service

The current implementation of BlobInputStream does
authorBruce Momjian <bruce@momjian.us>
Wed, 16 May 2001 03:29:01 +0000 (03:29 +0000)
committerBruce Momjian <bruce@momjian.us>
Wed, 16 May 2001 03:29:01 +0000 (03:29 +0000)
not properly handle 8-bit unsigned data as it blindly
casts the byte to an int, which java most helpfully
promotes to a signed type.  This causes problems when
you can only return -1 to indicated EOF.

The following patch fixes the bug and has been tested
locally on image data.

Chad David

src/interfaces/jdbc/org/postgresql/largeobject/BlobInputStream.java

index 646ea97..9a4b67d 100644 (file)
@@ -58,16 +58,24 @@ public class BlobInputStream extends InputStream {
    */
   public int read() throws java.io.IOException {
     try {
-      if(buffer==null || bpos>=buffer.length) {
+      if (buffer == null || bpos >= buffer.length) {
         buffer=lo.read(bsize);
         bpos=0;
       }
 
       // Handle EOF
-      if(bpos>=buffer.length)
+      if(bpos >= buffer.length) {
         return -1;
+      }
+
+      int ret = (buffer[bpos] & 0x7F);
+      if ((buffer[bpos] &0x80) == 0x80) {
+        ret |= 0x80;
+      }
 
-      return (int) buffer[bpos++];
+      bpos++;
+
+      return ret;
     } catch(SQLException se) {
       throw new IOException(se.toString());
     }
@@ -152,5 +160,4 @@ public class BlobInputStream extends InputStream {
     public boolean markSupported() {
        return true;
     }
-
-}
\ No newline at end of file
+}