Top Description Fields Constructors Methods
org.apache.derby.iapi.types

public Class HarmonySerialBlob

extends Object
implements Blob, Serializable, Cloneable
Class Inheritance
All Implemented Interfaces
java.lang.Cloneable, java.io.Serializable, java.sql.Blob
Imports
java.io.ByteArrayInputStream, .InputStream, .OutputStream, .Serializable, java.sql.Blob, .SQLException, org.apache.derby.shared.common.reference.SQLState, org.apache.derby.shared.common.error.StandardException

Copied from the Harmony project's implementation of javax.sql.rowset.serial.SerialBlob at subversion revision 946981.

Field Summary

Modifier and TypeField and Description
private Blob
private byte[]
private long
private long
private static final long

Constructor Summary

AccessConstructor and Description
public
HarmonySerialBlob(Blob
the given blob
blob
)

Constructs an instance by the given blob

public
HarmonySerialBlob(byte[]
the given buffer
buf
)

Constructs an instance by the given buf

Method Summary

Modifier and TypeMethod and Description
public void
free()

Implements java.sql.Blob.free.

This method frees the Blob object and releases the resources that it holds.

public InputStream
getBinaryStream()

Implements java.sql.Blob.getBinaryStream.

Returns an input stream of this SerialObject.

public InputStream
getBinaryStream(long
the offset to the first byte of the partial value to be retrieved. The first byte in the Blob is at position 1.
pos
,
long
the length in bytes of the partial value to be retrieved
length
)

Implements java.sql.Blob.getBinaryStream.

Returns an InputStream object that contains a partial Blob value, starting with the byte specified by pos, which is length bytes in length.

public byte[]
getBytes(long
the starting position of the array to be copied.
pos
,
int
the total length of bytes to be copied
length
)

Implements java.sql.Blob.getBytes.

Returns a copied array of this SerialObject, starting at the pos with the given length number.

public long

Returns:

an long value with the length of the SerialBlob in bytes
length
()

Implements java.sql.Blob.length.

Gets the number of bytes in this SerialBlob object.

public static SQLException
makeSQLException(String messageID, Object[] args)

Create a SQLException from Derby message arguments.

private boolean
match(byte[] bytes, int start, byte[] subBytes)

public long

Returns:

a long value with the position at which the pattern begins. -1 if the pattern is not found in this Blob.
position
(Blob
a Blob containing the pattern of data to search for in this Blob
pattern
,
long
the position within this Blob to start the search, where the first position in the Blob is 1
start
)

Implements java.sql.Blob.position.

Search for the position in this Blob at which a specified pattern begins, starting at a specified position within the Blob.

public long

Returns:

a long value with the position at which the pattern begins. -1 if the pattern is not found in this Blob.
position
(byte[]
a byte array containing the pattern of data to search for in this Blob
pattern
,
long
the position within this Blob to start the search, where the first position in the Blob is 1
start
)

Implements java.sql.Blob.position.

Search for the position in this Blob at which the specified pattern begins, starting at a specified position within the Blob.

public OutputStream
setBinaryStream(long
the position in the BLOB value at which to start writing; the first position is 1
pos
)

Implements java.sql.Blob.setBinaryStream.

Retrieves a stream that can be used to write to the BLOB value that this Blob object represents.

public int
setBytes(long
the position in the BLOB object at which to start writing; the first position is 1
pos
,
byte[]
the array of bytes to be written to the BLOB value that this Blob object represents
theBytes
)

Implements java.sql.Blob.setBytes.

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.

public int
setBytes(long
the position in the BLOB object at which to start writing; the first position is 1
pos
,
byte[]
the array of bytes to be written to this BLOB object
theBytes
,
int
the offset into the array bytes at which to start reading the bytes to be set
offset
,
int
the number of bytes to be written to the BLOB value from the array of bytes bytes
length
)

Implements java.sql.Blob.setBytes.

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.

public void
truncate(long
the length, in bytes, to which the BLOB value that this Blob object represents should be truncated
length
)

Implements java.sql.Blob.truncate.

Truncates the BLOB value that this Blob object represents to be len bytes in length.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

blobback to summary
private Blob blob
bufback to summary
private byte[] buf
lenback to summary
private long len
origLenback to summary
private long origLen
serialVersionUIDback to summary
private static final long serialVersionUID

Constructor Detail

HarmonySerialBlobback to summary
public HarmonySerialBlob(Blob blob) throws SQLException

Constructs an instance by the given blob

Parameters
blob:Blob

the given blob

Exceptions
SQLException:
if an error is encountered during serialization, or if blob is null
HarmonySerialBlobback to summary
public HarmonySerialBlob(byte[] buf)

Constructs an instance by the given buf

Parameters
buf:byte[]

the given buffer

Method Detail

freeback to summary
public void free() throws SQLException

Implements java.sql.Blob.free.

Doc from java.sql.Blob.free.

This method frees the Blob object and releases the resources that it holds. The object is invalid once the free method is called.

After free has been called, any attempt to invoke a method other than free will result in an SQLException being thrown. If free is called multiple times, the subsequent calls to free are treated as a no-op.

Exceptions
SQLException:
if an error occurs releasing the Blob's resources
getBinaryStreamback to summary
public InputStream getBinaryStream() throws SQLException

Implements java.sql.Blob.getBinaryStream.

Returns an input stream of this SerialObject.

Returns:InputStream

Doc from java.sql.Blob.getBinaryStream.

a stream containing the BLOB data

Exceptions
SQLException:
if an error is encountered
getBinaryStreamback to summary
public InputStream getBinaryStream(long pos, long length) throws SQLException

Implements java.sql.Blob.getBinaryStream.

Doc from java.sql.Blob.getBinaryStream.

Returns an InputStream object that contains a partial Blob value, starting with the byte specified by pos, which is length bytes in length.

Parameters
pos:long

the offset to the first byte of the partial value to be retrieved. The first byte in the Blob is at position 1.

length:long

the length in bytes of the partial value to be retrieved

Returns:InputStream

InputStream through which the partial Blob value can be read.

Exceptions
SQLException:
if pos is less than 1 or if pos is greater than the number of bytes in the Blob or if pos + length is greater than the number of bytes in the Blob
getBytesback to summary
public byte[] getBytes(long pos, int length) throws SQLException

Implements java.sql.Blob.getBytes.

Returns a copied array of this SerialObject, starting at the pos with the given length number. If pos + length - 1 is larger than the length of this SerialObject array, the length will be shortened to the length of array - pos + 1.

Parameters
pos:long

the starting position of the array to be copied.

length:int

the total length of bytes to be copied

Returns:byte[]

Doc from java.sql.Blob.getBytes.

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

Exceptions
SQLException:
if an error is encountered
lengthback to summary
public long length() throws SQLException

Implements java.sql.Blob.length.

Gets the number of bytes in this SerialBlob object.

Returns:long

an long value with the length of the SerialBlob in bytes

Exceptions
SQLException:
if an error is encoutnered
makeSQLExceptionback to summary
public static SQLException makeSQLException(String messageID, Object[] args)

Create a SQLException from Derby message arguments.

matchback to summary
private boolean match(byte[] bytes, int start, byte[] subBytes)
positionback to summary
public long position(Blob pattern, long start) throws SQLException

Implements java.sql.Blob.position.

Search for the position in this Blob at which a specified pattern begins, starting at a specified position within the Blob.

Parameters
pattern:Blob

a Blob containing the pattern of data to search for in this Blob

start:long

the position within this Blob to start the search, where the first position in the Blob is 1

Returns:long

a long value with the position at which the pattern begins. -1 if the pattern is not found in this Blob.

Exceptions
SQLException:
if an error occurs accessing the Blob, or if an error is encountered
positionback to summary
public long position(byte[] pattern, long start) throws SQLException

Implements java.sql.Blob.position.

Search for the position in this Blob at which the specified pattern begins, starting at a specified position within the Blob.

Parameters
pattern:byte[]

a byte array containing the pattern of data to search for in this Blob

start:long

the position within this Blob to start the search, where the first position in the Blob is 1

Returns:long

a long value with the position at which the pattern begins. -1 if the pattern is not found in this Blob.

Exceptions
SQLException:
if an error is encountered, or if an error occurs accessing the Blob
setBinaryStreamback to summary
public OutputStream setBinaryStream(long pos) throws SQLException

Implements java.sql.Blob.setBinaryStream.

Doc from java.sql.Blob.setBinaryStream.

Retrieves a stream that can be used to write to the BLOB value that this Blob object represents. The stream begins at position pos. The bytes written to the stream will overwrite the existing bytes in the Blob object starting at the position pos. If the end of the Blob value is reached while writing to the stream, then the length of the Blob value will be increased to accommodate the extra bytes.

Note

If the value specified for pos is greater than the length+1 of the BLOB value then the behavior is undefined. Some JDBC drivers may throw an SQLException while other drivers may support this operation.

Parameters
pos:long

the position in the BLOB value at which to start writing; the first position is 1

Returns:OutputStream

a java.io.OutputStream object to which data can be written

Exceptions
SQLException:
if there is an error accessing the BLOB value or if pos is less than 1
setBytesback to summary
public int setBytes(long pos, byte[] theBytes) throws SQLException

Implements java.sql.Blob.setBytes.

Doc from java.sql.Blob.setBytes.

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. The array of bytes will overwrite the existing bytes in the Blob object starting at the position pos. If the end of the Blob value is reached while writing the array of bytes, then the length of the Blob value will be increased to accommodate the extra bytes.

Note

If the value specified for pos is greater than the length+1 of the BLOB value then the behavior is undefined. Some JDBC drivers may throw an SQLException while other drivers may support this operation.

Parameters
pos:long

the position in the BLOB object at which to start writing; the first position is 1

theBytes:byte[]

the array of bytes to be written to the BLOB value that this Blob object represents

Returns:int

the number of bytes written

Exceptions
SQLException:
if there is an error accessing the BLOB value or if pos is less than 1
setBytesback to summary
public int setBytes(long pos, byte[] theBytes, int offset, int length) throws SQLException

Implements java.sql.Blob.setBytes.

Doc from java.sql.Blob.setBytes.

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. Writing starts at position pos in the BLOB value; len bytes from the given byte array are written. The array of bytes will overwrite the existing bytes in the Blob object starting at the position pos. If the end of the Blob value is reached while writing the array of bytes, then the length of the Blob value will be increased to accommodate the extra bytes.

Note

If the value specified for pos is greater than the length+1 of the BLOB value then the behavior is undefined. Some JDBC drivers may throw an SQLException while other drivers may support this operation.

Parameters
pos:long

the position in the BLOB object at which to start writing; the first position is 1

theBytes:byte[]

the array of bytes to be written to this BLOB object

offset:int

the offset into the array bytes at which to start reading the bytes to be set

length:int

the number of bytes to be written to the BLOB value from the array of bytes bytes

Returns:int

the number of bytes written

Exceptions
SQLException:
if there is an error accessing the BLOB value or if pos is less than 1
truncateback to summary
public void truncate(long length) throws SQLException

Implements java.sql.Blob.truncate.

Doc from java.sql.Blob.truncate.

Truncates the BLOB value that this Blob object represents to be len bytes in length.

Note

If the value specified for pos is greater than the length+1 of the BLOB value then the behavior is undefined. Some JDBC drivers may throw an SQLException while other drivers may support this operation.

Parameters
length:long

the length, in bytes, to which the BLOB value that this Blob object represents should be truncated

Exceptions
SQLException:
if there is an error accessing the BLOB value or if len is less than 0