de.mguennewig.pobjects
Class PObjBlob

java.lang.Object
  extended by de.mguennewig.pobjects.PObjBlob
All Implemented Interfaces:
java.sql.Blob

public class PObjBlob
extends java.lang.Object
implements java.sql.Blob

This class provides a portable way to create a BLOB.

NOTE: This class is only suitable to create a BLOB to put data into the database. You will get back a database specific BLOB when reading.

Author:
Michael Günnewig
See Also:
BlobType

Field Summary
static java.sql.Blob EMPTY_BLOB
          An empty unmodifiable BLOB.
 
Constructor Summary
PObjBlob()
          Creates a new empty BLOB.
PObjBlob(byte[] data)
          Creates a new BLOB for the given data.
PObjBlob(java.io.File file)
          Creates a new BLOB that uses the specified file for the data.
 
Method Summary
 void free()
           
 java.io.InputStream getBinaryStream()
          Retrieves the BLOB value designated by this Blob instance as a stream.
 java.io.InputStream getBinaryStream(long pos, long length)
           
 byte[] getBytes(long pos, int length)
          Retrieves all or part of the BLOB value that this Blob object represents, as an array of bytes.
 long length()
          Returns the number of bytes in the BLOB value designated by this Blob object.
 long position(java.sql.Blob pattern, long start)
          Retrieves the byte position in the BLOB value designated by this Blob object at which pattern begins.
 long position(byte[] pattern, long start)
          Retrieves the byte position at which the specified byte array pattern begins within the BLOB value that this Blob object represents.
 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)
          Truncates the BLOB value that this Blob object represents to be len bytes in length.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

EMPTY_BLOB

public static final java.sql.Blob EMPTY_BLOB
An empty unmodifiable BLOB.

Constructor Detail

PObjBlob

public PObjBlob()
Creates a new empty BLOB.


PObjBlob

public PObjBlob(byte[] data)
Creates a new BLOB for the given data.


PObjBlob

public PObjBlob(java.io.File file)
Creates a new BLOB that uses the specified file for the data.

Method Detail

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
Throws:
java.sql.SQLException

getBytes

public byte[] getBytes(long pos,
                       int length)
                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
Throws:
java.sql.SQLException

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

position

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

Specified by:
position in interface java.sql.Blob
Throws:
java.sql.SQLException

position

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

Specified by:
position in interface java.sql.Blob
Throws:
java.sql.SQLException

setBinaryStream

public java.io.OutputStream setBinaryStream(long pos)
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

setBytes

public final 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.

Specified by:
setBytes in interface java.sql.Blob

setBytes

public 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.

Specified by:
setBytes in interface java.sql.Blob

truncate

public void truncate(long len)
Truncates the BLOB value that this Blob object represents to be len bytes in length.

Specified by:
truncate in interface java.sql.Blob

free

public void free()
Specified by:
free in interface java.sql.Blob

getBinaryStream

public java.io.InputStream getBinaryStream(long pos,
                                           long length)
                                    throws java.sql.SQLException
Specified by:
getBinaryStream in interface java.sql.Blob
Throws:
java.sql.SQLException