Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package org.firebirdsql.jdbc;
  
  
  
 public class FBBlobOutputStream extends OutputStream 
     implements FirebirdBlob.BlobOutputStream
 {
 
     private IscBlobHandle blobHandle;
     private FBBlob owner;
 
     FBBlobOutputStream(FBBlob ownerthrows SQLException {
         
         this. = owner;
         
         Object syncObject = owner.getSynchronizationObject();
         
         synchronized(syncObject) {
             try {
                 DatabaseParameterBuffer dpb = owner.gdsHelper.getDatabaseParameterBuffer();
                 
                 boolean useStreamBlobs = 
                     dpb.hasArgument(.);
                 
                  = owner.gdsHelper.createBlob(!useStreamBlobs);
                 
             } catch (GDSException ge) {
                 throw new FBSQLException(ge);
             }
         }
         
         if (owner.isNew) {
             owner.setBlobId(.getBlobId());
         }
     }
     
     public void seek(int positionint seekModethrows SQLException {
         try {
             ..seekBlob(positionseekMode);
         } catch(GDSException ex) {
             throw new FBSQLException(ex);
         }
     }
     
     public long length() throws IOException {
         
         Object syncObject = .getSynchronizationObject();
         
         synchronized(syncObject) {
             try {
                 byte[] info = ..getBlobInfo(
                     new byte[] {.}, 20);
 
                 return .interpretLength(info, 0);
             } catch (GDSException ex) {
                 throw new IOException(ex.getMessage());
             } catch (SQLException ex) {
                 throw new IOException(ex.getMessage());
             }
         }
     }
 
     public void write(int bthrows IOException {
         //This won't be called, don't implement
         throw new IOException("FBBlobOutputStream.write(int b) not implemented");
     }
 
     public void writeSegment(byte[] bufthrows GDSException {
         Object syncObject = .getSynchronizationObject();
         synchronized(syncObject) {
             ..putBlobSegment(buf);
         }
     }
     
     public void write(byte[] bint offint lenthrows IOException {
         try {
             if (off == 0 && len == b.length && len < .) {
                 /*
                  * If we are just writing the entire byte array, we need to
                  * do nothing but just write it over
                  */
                 writeSegment(b);
             } else {
                 /*
                  * In this case, we need to chunk it over since <code>putBlobSegment</code>
                  * cannot currently support length and offset.
                  */
                 int chunk = .;
                 int lastChunk = 0;
                 byte[] buf = null;
                 while (len > 0) {
                     if (len < chunkchunk = len;
 
                     // this allows us to reused the chunk if its size has
                    // not changed
                    if (chunk != lastChunk) {
                        buf = new byte[chunk];
                        lastChunk = chunk;
                    }
                    System.arraycopy(boffbuf, 0, chunk);
                    writeSegment(buf);
                    len -= chunk;
                    off += chunk;
                }
            }
        } catch (GDSException ge) {
            throw new IOException("Problem writing to FBBlobOutputStream: "
                    + ge);
        }
    }
    public void close() throws IOException {
        if ( != null) {
            try {
                
                Object syncObject = .getSynchronizationObject();
                
                synchronized(syncObject) {
                    ..closeBlob();
                }
                
                .setBlobId(.getBlobId());
                
            } catch (GDSException ge) {
                throw new IOException("could not close blob: " + ge);
            }
            
             = null;
        }
    }
New to GrepCode? Check out our FAQ X