Package org.apache.cayenne.util
Class MemoryBlob
java.lang.Object
org.apache.cayenne.util.MemoryBlob
- All Implemented Interfaces:
Blob
A Blob implementation that stores content in memory.
This implementation is based on jdbcBlob from HSQLDB (copyright HSQL Development Group).
- Since:
- 1.2
-
Constructor Summary
ConstructorsConstructorDescriptionMemoryBlob
(byte[] data) Constructs a new MemoryBlob instance wrapping the given octet sequence. -
Method Summary
Modifier and TypeMethodDescriptionvoid
free()
Retrieves theBLOB
value designated by thisBlob
instance as a stream.getBinaryStream
(long arg0, long arg1) byte[]
getBytes
(long pos, int length) Retrieves all or part of theBLOB
value that thisBlob
object represents, as an array of bytes.long
length()
Returns the number of bytes in theBLOB
value designated by thisBlob
object.long
position
(byte[] pattern, long start) Retrieves the byte position at which the specified byte arraypattern
begins within theBLOB
value that thisBlob
object represents.long
Retrieves the byte position in theBLOB
value designated by thisBlob
object at whichpattern
begins.setBinaryStream
(long pos) Always throws an exception.int
setBytes
(long pos, byte[] bytes) Always throws an exception.int
setBytes
(long pos, byte[] bytes, int offset, int len) Always throws an exception.void
truncate
(long len) Truncates theBLOB
value that thisBlob
object represents to belen
bytes in length.
-
Constructor Details
-
MemoryBlob
public MemoryBlob() -
MemoryBlob
public MemoryBlob(byte[] data) Constructs a new MemoryBlob instance wrapping the given octet sequence.- Parameters:
data
- the octet sequence representing the Blob value- Throws:
CayenneRuntimeException
- if the argument is null
-
-
Method Details
-
length
Returns the number of bytes in theBLOB
value designated by thisBlob
object.- Specified by:
length
in interfaceBlob
- Returns:
- length of the
BLOB
in bytes - Throws:
SQLException
- if there is an error accessing the length of theBLOB
-
getBytes
Retrieves all or part of theBLOB
value that thisBlob
object represents, as an array of bytes. Thisbyte
array contains up tolength
consecutive bytes starting at positionpos
.The official specification is ambiguous in that it does not precisely indicate the policy to be observed when pos > this.length() - length. One policy would be to retrieve the octets from pos to this.length(). Another would be to throw an exception. This implementation observes the later policy.
- Specified by:
getBytes
in interfaceBlob
- Parameters:
pos
- the ordinal position of the first byte in theBLOB
value to be extracted; the first byte is at position 1length
- the number of consecutive bytes to be copied- Returns:
- a byte array containing up to
length
consecutive bytes from theBLOB
value designated by thisBlob
object, starting with the byte at positionpos
- Throws:
SQLException
- if there is an error accessing theBLOB
value
-
getBinaryStream
Retrieves theBLOB
value designated by thisBlob
instance as a stream.- Specified by:
getBinaryStream
in interfaceBlob
- Returns:
- a stream containing the
BLOB
data - Throws:
SQLException
- if there is an error accessing theBLOB
value
-
position
Retrieves the byte position at which the specified byte arraypattern
begins within theBLOB
value that thisBlob
object represents. The search forpattern
begins at positionstart
.- Specified by:
position
in interfaceBlob
- Parameters:
pattern
- the byte array for which to searchstart
- the position at which to begin searching; the first position is 1- Returns:
- the position at which the pattern appears, else -1
- Throws:
SQLException
- if there is an error accessing theBLOB
-
position
Retrieves the byte position in theBLOB
value designated by thisBlob
object at whichpattern
begins. The search begins at positionstart
.- Specified by:
position
in interfaceBlob
- Parameters:
pattern
- theBlob
object designating theBLOB
value for which to searchstart
- the position in theBLOB
value at which to begin searching; the first position is 1- Returns:
- the position at which the pattern begins, else -1
- Throws:
SQLException
- if there is an error accessing theBLOB
value
-
setBytes
Always throws an exception.- Specified by:
setBytes
in interfaceBlob
- Throws:
SQLException
-
setBytes
Always throws an exception.- Specified by:
setBytes
in interfaceBlob
- Throws:
SQLException
-
setBinaryStream
Always throws an exception.- Specified by:
setBinaryStream
in interfaceBlob
- Throws:
SQLException
-
truncate
Truncates theBLOB
value that thisBlob
object represents to belen
bytes in length.- Specified by:
truncate
in interfaceBlob
- Parameters:
len
- the length, in bytes, to which theBLOB
value that thisBlob
object represents should be truncated- Throws:
SQLException
- if there is an error accessing theBLOB
value
-
free
- Specified by:
free
in interfaceBlob
- Throws:
SQLException
- Since:
- 3.0
-
getBinaryStream
- Specified by:
getBinaryStream
in interfaceBlob
- Throws:
SQLException
- Since:
- 3.0
-