org.sqlite.jdbc
Class JdbcBlob

java.lang.Object
  extended by org.sqlite.jdbc.JdbcBlob
All Implemented Interfaces:
java.sql.Blob, Closeable

public class JdbcBlob
extends java.lang.Object
implements java.sql.Blob, Closeable


Constructor Summary
JdbcBlob(Closeable owner, Blob blob)
          Create JdbcBlob object from the sqlite3_blob object.
JdbcBlob(Closeable owner, SWIGTYPE_p_void blob, long len)
          Create JdbcBlob object from the void pointer.
 
Method Summary
 void close()
          Closes this BLOB object.
 java.io.InputStream getBinaryStream()
          Retrieves the BLOB value designated by this Blob instance as a stream.
 byte[] getBytes(long pos, int len)
          Retrieves all or part of the BLOB value that this Blob object represents, as an array of bytes.
 boolean isClosed()
          Retrieves whether this BLOB object has been closed.
 long length()
          Returns the number of bytes in the BLOB value designated by this Blob object.
 long position(java.sql.Blob pattern, long start)
          invoke position(byte[], long) method.
 long position(byte[] pattern, long start)
          Retrieves by the Boyer-Moore algorithm.
 java.io.OutputStream setBinaryStream(long pos)
          Retrieves a stream that can be used to write to the BLOB value that this Blob object represents.
 int setBytes(long pos, byte[] bytes)
          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)
          Writes all or part of the given byte array to the BLOB value that this Blob object represents and returns the number of bytes written.
 void truncate(long len)
          Not supporetd yet.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

JdbcBlob

public JdbcBlob(Closeable owner,
                SWIGTYPE_p_void blob,
                long len)
Create JdbcBlob object from the void pointer.

Parameters:
owner - the owner Closeable object
blob - the pointer of blob
len - the number of bytes

JdbcBlob

public JdbcBlob(Closeable owner,
                Blob blob)
         throws java.sql.SQLException
Create JdbcBlob object from the sqlite3_blob object.

Parameters:
owner - the owner Closeable object
blob - the sqlite3_blob object
Throws:
java.sql.SQLException - When this method is called on a closed blob.
Method Detail

length

public long length()
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

getBytes

public byte[] getBytes(long pos,
                       int len)
                throws java.sql.SQLException
Retrieves all or part of the BLOB value that this Blob object represents, as an array of bytes.

Specified by:
getBytes in interface java.sql.Blob
Parameters:
pos - the ordinal position of the first byte in the BLOB value to be extracted; the first byte is at position 1
len - the number of consecutive bytes to be copied; the value for length must be 0 or greater
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 - When this method is called on a closed connection. When pos is less than 1 or length is less than 0

getBinaryStream

public java.io.InputStream getBinaryStream()
                                    throws java.sql.SQLException
Retrieves the BLOB value 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

position

public long position(byte[] pattern,
                     long start)
              throws java.sql.SQLException
Retrieves by the Boyer-Moore algorithm.

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 - When this method is called on a closed connection.
See Also:
Boyer-Moore algorithm, getBytes(long, int)

position

public long position(java.sql.Blob pattern,
                     long start)
              throws java.sql.SQLException
invoke position(byte[], long) method.

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 - When this method is called on a closed connection.
See Also:
position(byte[], long)

setBytes

public int setBytes(long pos,
                    byte[] bytes)
             throws java.sql.SQLException
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; the first position is 1
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
See Also:
setBytes(long, byte[], int, int)

setBytes

public int setBytes(long pos,
                    byte[] bytes,
                    int offset,
                    int len)
             throws java.sql.SQLException
Writes all or part of the given byte array to the BLOB value that this Blob object represents 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; the first position is 1
bytes - the array of bytes to be written to this BLOB object
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
See Also:
setBinaryStream(long), OutputStream.write(byte[], int, int)

setBinaryStream

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

Specified by:
setBinaryStream in interface java.sql.Blob
Parameters:
pos - the position in the BLOB value at which to start writing; the first position is 1
Returns:
a java.io.OutputStream object to which data can be written
Throws:
java.sql.SQLException - if there is an error accessing the BLOB value or if pos is less than 1

truncate

public void truncate(long len)
Not supporetd yet.

Specified by:
truncate in interface java.sql.Blob
Throws:
java.lang.UnsupportedOperationException

close

public void close()
Closes this BLOB object.

Specified by:
close in interface Closeable

isClosed

public boolean isClosed()
Retrieves whether this BLOB object has been closed.

Specified by:
isClosed in interface Closeable
Returns:
true if this BLOB object is closed. false if it is still open.