org.apache.derby.impl.jdbc
Class EmbedBlob

java.lang.Object
  extended byorg.apache.derby.impl.jdbc.ConnectionChild
      extended byorg.apache.derby.impl.jdbc.EmbedBlob
All Implemented Interfaces:
java.sql.Blob

class EmbedBlob
extends ConnectionChild
implements java.sql.Blob


Field Summary
private  BinaryToRawStream biStream
           
private static int BLOB_BUF_SIZE
           
private  byte[] buf
           
private  boolean isBytes
           
private  byte[] myBytes
           
private  java.io.InputStream myStream
           
private  long pos
           
 
Fields inherited from class org.apache.derby.impl.jdbc.ConnectionChild
CLOSE, factory, localConn, NOCLOSE
 
Constructor Summary
protected EmbedBlob(DataValueDescriptor dvd, EmbedConnection con)
           
 
Method Summary
private  boolean checkMatch(java.sql.Blob pattern)
           
private  boolean checkMatch(byte[] pattern)
           
protected  void finalize()
           
 java.io.InputStream getBinaryStream()
          Retrieves the BLOB designated by this Blob instance as a stream.
 byte[] getBytes(long startPos, int length)
          Returns as an array of bytes part or all of the BLOB value that this Blob object designates.
private  java.sql.SQLException handleMyExceptions(java.lang.Throwable t)
           
 long length()
          Returns the number of bytes in the BLOB value designated by this Blob object.
 long position(java.sql.Blob pattern, long start)
          Determines the byte position in the BLOB value designated by this Blob object at which pattern begins.
 long position(byte[] pattern, long start)
          Determines the byte position at which the specified byte pattern begins within the BLOB value that this Blob object represents.
private  int read()
           
 java.io.OutputStream setBinaryStream(long pos)
          JDBC 3.0 Retrieves a stream that can be used to write to the BLOB value that this Blob object represents.
 int setBytes(long pos, byte[] bytes)
          JDBC 3.0 Writes the given array of bytes to the BLOB value that this Blob object represents, starting at position pos, and returns the number of bytes written.
 int setBytes(long pos, byte[] bytes, int offset, int len)
          JDBC 3.0 Writes all or part of the given array of byte array to the BLOB value that this Blob object represents and returns the number of bytes written.
private  void setPosition(long newPos)
           
 void truncate(long len)
          JDBC 3.0 Truncates the BLOB value that this Blob object represents to be len bytes in length.
 
Methods inherited from class org.apache.derby.impl.jdbc.ConnectionChild
commitIfAutoCommit, commitIfNeeded, getCal, getConnectionSynchronization, getContextManager, getDatabase, getEmbedConnection, handleException, handleException, needCommit, newSQLException, newSQLException, newSQLException, restoreContextStack, setupContextStack
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

isBytes

private boolean isBytes

myStream

private java.io.InputStream myStream

myBytes

private byte[] myBytes

pos

private long pos

biStream

private BinaryToRawStream biStream

BLOB_BUF_SIZE

private static int BLOB_BUF_SIZE

buf

private byte[] buf
Constructor Detail

EmbedBlob

protected EmbedBlob(DataValueDescriptor dvd,
                    EmbedConnection con)
             throws StandardException
Method Detail

setPosition

private void setPosition(long newPos)
                  throws StandardException,
                         java.io.IOException
Throws:
StandardException
java.io.IOException

read

private int read()
          throws java.io.IOException
Throws:
java.io.IOException

length

public long length()
            throws java.sql.SQLException
Returns the number of bytes in the BLOB value designated by this Blob object.

Specified by:
length in interface java.sql.Blob
Returns:
length of the BLOB in bytes
Throws:
java.sql.SQLException - if there is an error accessing the length of the BLOB

getBytes

public byte[] getBytes(long startPos,
                       int length)
                throws java.sql.SQLException
Returns as an array of bytes part or all of the BLOB value that this Blob object designates. The byte array contains up to length consecutive bytes starting at position pos.

Specified by:
getBytes in interface java.sql.Blob
Parameters:
length - is the number of consecutive bytes to be copied
Returns:
a byte array containing up to length consecutive bytes from the BLOB value designated by this Blob object, starting with the byte at position pos.
Throws:
java.sql.SQLException - if there is an error accessing the BLOB NOTE: return new byte[0] if startPos is too large

getBinaryStream

public java.io.InputStream getBinaryStream()
                                    throws java.sql.SQLException
Retrieves the BLOB designated by this Blob instance as a stream.

Specified by:
getBinaryStream in interface java.sql.Blob
Returns:
a stream containing the BLOB data
Throws:
java.sql.SQLException - if there is an error accessing the BLOB

position

public long position(byte[] pattern,
                     long start)
              throws java.sql.SQLException
Determines the byte position at which the specified byte pattern begins within the BLOB value that this Blob object represents. The search for patternstart

Specified by:
position in interface java.sql.Blob
Parameters:
pattern - the byte array for which to search
start - the position at which to begin searching; the first position is 1
Returns:
the position at which the pattern appears, else -1.
Throws:
java.sql.SQLException - if there is an error accessing the BLOB

checkMatch

private boolean checkMatch(byte[] pattern)
                    throws java.io.IOException
Throws:
java.io.IOException

position

public long position(java.sql.Blob pattern,
                     long start)
              throws java.sql.SQLException
Determines the byte position in the BLOB value designated by this Blob object at which pattern begins. The search begins at position start.

Specified by:
position in interface java.sql.Blob
Parameters:
pattern - the Blob object designating the BLOB value for which to search
start - the position in the BLOB value at which to begin searching; the first position is 1
Returns:
the position at which the pattern begins, else -1
Throws:
java.sql.SQLException - if there is an error accessing the BLOB

checkMatch

private boolean checkMatch(java.sql.Blob pattern)
                    throws java.io.IOException
Throws:
java.io.IOException

handleMyExceptions

private java.sql.SQLException handleMyExceptions(java.lang.Throwable t)
                                          throws java.sql.SQLException
Throws:
java.sql.SQLException

finalize

protected void finalize()

setBytes

public int setBytes(long pos,
                    byte[] bytes)
             throws java.sql.SQLException
JDBC 3.0 Writes the given array of bytes to the BLOB value that this Blob object represents, starting at position pos, and returns the number of bytes written.

Specified by:
setBytes in interface java.sql.Blob
Parameters:
pos - - the position in the BLOB object at which to start writing
bytes - - the array of bytes to be written to the BLOB value that this Blob object represents
Returns:
the number of bytes written
Throws:
java.sql.SQLException - Feature not implemented for now.

setBytes

public int setBytes(long pos,
                    byte[] bytes,
                    int offset,
                    int len)
             throws java.sql.SQLException
JDBC 3.0 Writes all or part of the given array of byte array to the BLOB value that this Blob object represents and returns the number of bytes written. Writing starts at position pos in the BLOB value; len bytes from the given byte array are written.

Specified by:
setBytes in interface java.sql.Blob
Parameters:
pos - - the position in the BLOB object at which to start writing
bytes - - the array of bytes to be written to the BLOB value that this Blob object represents
offset - - the offset into the array bytes at which to start reading the bytes to be set
len - - the number of bytes to be written to the BLOB value from the array of bytes bytes
Returns:
the number of bytes written
Throws:
java.sql.SQLException - Feature not implemented for now.

setBinaryStream

public java.io.OutputStream setBinaryStream(long pos)
                                     throws java.sql.SQLException
JDBC 3.0 Retrieves a stream that can be used to write to the BLOB value that this Blob object represents. The stream begins at position pos.

Specified by:
setBinaryStream in interface java.sql.Blob
Parameters:
pos - - the position in the BLOB object at which to start writing
Returns:
a java.io.OutputStream object to which data can be written
Throws:
java.sql.SQLException - Feature not implemented for now.

truncate

public void truncate(long len)
              throws java.sql.SQLException
JDBC 3.0 Truncates the BLOB value that this Blob object represents to be len bytes in length.

Specified by:
truncate in interface java.sql.Blob
Parameters:
len - - the length, in bytes, to which the BLOB value that this Blob object represents should be truncated
Throws:
java.sql.SQLException - Feature not implemented for now.


Apache Derby V10.0 Engine Documentation - Copyright © 1997,2004 The Apache Software Foundation or its licensors, as applicable.