Package org.apache.cayenne.util
Class MemoryBlob
- java.lang.Object
-
- org.apache.cayenne.util.MemoryBlob
-
-
Constructor Summary
Constructors Constructor Description MemoryBlob()
MemoryBlob(byte[] data)
Constructs a new MemoryBlob instance wrapping the given octet sequence.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
free()
InputStream
getBinaryStream()
Retrieves theBLOB
value designated by thisBlob
instance as a stream.InputStream
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
position(Blob pattern, long start)
Retrieves the byte position in theBLOB
value designated by thisBlob
object at whichpattern
begins.OutputStream
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 Detail
-
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 Detail
-
length
public long length() throws SQLException
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
public byte[] getBytes(long pos, int length) throws SQLException
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
public InputStream getBinaryStream() throws SQLException
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
public long position(byte[] pattern, long start) throws SQLException
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
public long position(Blob pattern, long start) throws SQLException
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
public int setBytes(long pos, byte[] bytes) throws SQLException
Always throws an exception.- Specified by:
setBytes
in interfaceBlob
- Throws:
SQLException
-
setBytes
public int setBytes(long pos, byte[] bytes, int offset, int len) throws SQLException
Always throws an exception.- Specified by:
setBytes
in interfaceBlob
- Throws:
SQLException
-
setBinaryStream
public OutputStream setBinaryStream(long pos) throws SQLException
Always throws an exception.- Specified by:
setBinaryStream
in interfaceBlob
- Throws:
SQLException
-
truncate
public void truncate(long len) throws SQLException
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
public void free() throws SQLException
- Specified by:
free
in interfaceBlob
- Throws:
SQLException
- Since:
- 3.0
-
getBinaryStream
public InputStream getBinaryStream(long arg0, long arg1) throws SQLException
- Specified by:
getBinaryStream
in interfaceBlob
- Throws:
SQLException
- Since:
- 3.0
-
-