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 TypeMethodDescriptionvoidfree()Retrieves theBLOBvalue designated by thisBlobinstance as a stream.getBinaryStream(long arg0, long arg1) byte[]getBytes(long pos, int length) Retrieves all or part of theBLOBvalue that thisBlobobject represents, as an array of bytes.longlength()Returns the number of bytes in theBLOBvalue designated by thisBlobobject.longposition(byte[] pattern, long start) Retrieves the byte position at which the specified byte arraypatternbegins within theBLOBvalue that thisBlobobject represents.longRetrieves the byte position in theBLOBvalue designated by thisBlobobject at whichpatternbegins.setBinaryStream(long pos) Always throws an exception.intsetBytes(long pos, byte[] bytes) Always throws an exception.intsetBytes(long pos, byte[] bytes, int offset, int len) Always throws an exception.voidtruncate(long len) Truncates theBLOBvalue that thisBlobobject represents to belenbytes 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 theBLOBvalue designated by thisBlobobject.- Specified by:
lengthin interfaceBlob- Returns:
- length of the
BLOBin bytes - Throws:
SQLException- if there is an error accessing the length of theBLOB
-
getBytes
Retrieves all or part of theBLOBvalue that thisBlobobject represents, as an array of bytes. Thisbytearray contains up tolengthconsecutive 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:
getBytesin interfaceBlob- Parameters:
pos- the ordinal position of the first byte in theBLOBvalue 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
lengthconsecutive bytes from theBLOBvalue designated by thisBlobobject, starting with the byte at positionpos - Throws:
SQLException- if there is an error accessing theBLOBvalue
-
getBinaryStream
Retrieves theBLOBvalue designated by thisBlobinstance as a stream.- Specified by:
getBinaryStreamin interfaceBlob- Returns:
- a stream containing the
BLOBdata - Throws:
SQLException- if there is an error accessing theBLOBvalue
-
position
Retrieves the byte position at which the specified byte arraypatternbegins within theBLOBvalue that thisBlobobject represents. The search forpatternbegins at positionstart.- Specified by:
positionin 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 theBLOBvalue designated by thisBlobobject at whichpatternbegins. The search begins at positionstart.- Specified by:
positionin interfaceBlob- Parameters:
pattern- theBlobobject designating theBLOBvalue for which to searchstart- the position in theBLOBvalue 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 theBLOBvalue
-
setBytes
Always throws an exception.- Specified by:
setBytesin interfaceBlob- Throws:
SQLException
-
setBytes
Always throws an exception.- Specified by:
setBytesin interfaceBlob- Throws:
SQLException
-
setBinaryStream
Always throws an exception.- Specified by:
setBinaryStreamin interfaceBlob- Throws:
SQLException
-
truncate
Truncates theBLOBvalue that thisBlobobject represents to belenbytes in length.- Specified by:
truncatein interfaceBlob- Parameters:
len- the length, in bytes, to which theBLOBvalue that thisBlobobject represents should be truncated- Throws:
SQLException- if there is an error accessing theBLOBvalue
-
free
- Specified by:
freein interfaceBlob- Throws:
SQLException- Since:
- 3.0
-
getBinaryStream
- Specified by:
getBinaryStreamin interfaceBlob- Throws:
SQLException- Since:
- 3.0
-