Package org.apache.cayenne.util
Class MemoryBlob
java.lang.Object
org.apache.cayenne.util.MemoryBlob
- All Implemented Interfaces:
- Blob
public class MemoryBlob extends Object implements 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 SummaryConstructors Constructor Description MemoryBlob()MemoryBlob(byte[] data)Constructs a new MemoryBlob instance wrapping the given octet sequence.
- 
Method SummaryModifier and Type Method Description voidfree()InputStreamgetBinaryStream()Retrieves theBLOBvalue designated by thisBlobinstance as a stream.InputStreamgetBinaryStream(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.longposition(Blob pattern, long start)Retrieves the byte position in theBLOBvalue designated by thisBlobobject at whichpatternbegins.OutputStreamsetBinaryStream(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- 
MemoryBlobpublic MemoryBlob()
- 
MemoryBlobpublic 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- 
lengthReturns the number of bytes in theBLOBvalue designated by thisBlobobject.- Specified by:
- lengthin interface- Blob
- Returns:
- length of the BLOBin bytes
- Throws:
- SQLException- if there is an error accessing the length of the- BLOB
 
- 
getBytesRetrieves 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 interface- Blob
- Parameters:
- pos- the ordinal position of the first byte in the- BLOBvalue to be extracted; the first byte is at position 1
- length- 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 the- BLOBvalue
 
- 
getBinaryStreamRetrieves theBLOBvalue designated by thisBlobinstance as a stream.- Specified by:
- getBinaryStreamin interface- Blob
- Returns:
- a stream containing the BLOBdata
- Throws:
- SQLException- if there is an error accessing the- BLOBvalue
 
- 
positionRetrieves the byte position at which the specified byte arraypatternbegins within theBLOBvalue that thisBlobobject represents. The search forpatternbegins at positionstart.- Specified by:
- positionin interface- 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:
- SQLException- if there is an error accessing the- BLOB
 
- 
positionRetrieves the byte position in theBLOBvalue designated by thisBlobobject at whichpatternbegins. The search begins at positionstart.- Specified by:
- positionin interface- Blob
- Parameters:
- pattern- the- Blobobject designating the- BLOBvalue for which to search
- start- the position in the- BLOBvalue 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 the- BLOBvalue
 
- 
setBytesAlways throws an exception.- Specified by:
- setBytesin interface- Blob
- Throws:
- SQLException
 
- 
setBytesAlways throws an exception.- Specified by:
- setBytesin interface- Blob
- Throws:
- SQLException
 
- 
setBinaryStreamAlways throws an exception.- Specified by:
- setBinaryStreamin interface- Blob
- Throws:
- SQLException
 
- 
truncateTruncates theBLOBvalue that thisBlobobject represents to belenbytes in length.- Specified by:
- truncatein interface- Blob
- Parameters:
- len- the length, in bytes, to which the- BLOBvalue that this- Blobobject represents should be truncated
- Throws:
- SQLException- if there is an error accessing the- BLOBvalue
 
- 
free- Specified by:
- freein interface- Blob
- Throws:
- SQLException
- Since:
- 3.0
 
- 
getBinaryStream- Specified by:
- getBinaryStreamin interface- Blob
- Throws:
- SQLException
- Since:
- 3.0
 
 
-