Class ClientBlob
java.lang.Object
org.apache.derby.client.am.Lob
org.apache.derby.client.am.ClientBlob
- All Implemented Interfaces:
Blob, UnitOfWorkListener
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) InputStream(package private) byte[](package private) intFields inherited from class Lob
agent_, ASCII_STREAM, BINARY_STREAM, BINARY_STRING, CHARACTER_STREAM, dataType_, INVALID_LOCATOR, isValid_, LOCATOR, locator_, STRING, UNICODE_STREAM -
Constructor Summary
ConstructorsConstructorDescriptionClientBlob(byte[] binaryString, Agent agent, int dataOffset) ClientBlob(Agent agent, int locator) Create aBlobobject for a Blob value stored on the server and indentified bylocator.ClientBlob(Agent agent, InputStream binaryStream) Create a newBlobfrom a stream with unknown length.ClientBlob(Agent agent, InputStream binaryStream, int length) -
Method Summary
Modifier and TypeMethodDescriptionprivate longbinaryStringPosition(byte[] pattern, long start) voidfree()This method frees theBlobobject and releases the resources that it holds.getBinaryStream(long pos, long length) Returns anInputStreamobject that contains a partialBlobvalue, starting with the byte specified by pos, which is length bytes in length.(package private) InputStreambyte[]getBytes(long pos, int length) Returns as an array of bytes part or all of theBLOBvalue that thisBlobobject designates.private byte[]getBytesX(long pos, int length) (package private) longGet the length in bytes of theBlobvalue represented by this locator basedobject. booleanbooleanprivate booleanisSubString(byte[] pattern, int index) longlength()protected voidMaterialize the stream used for input to the database.longposition(byte[] pattern, long start) longprivate longpositionX(byte[] pattern, long start) private longsetBinaryStream(long pos) intsetBytes(long pos, byte[] bytes) intsetBytes(long pos, byte[] bytes, int offset, int len) (package private) intsetBytesX(long pos, byte[] bytes, int offset, int len) voidtruncate(long len) Methods inherited from class Lob
checkForClosedConnection, checkForLocatorValidity, checkPosAndLength, checkValidity, completeLocalCommit, completeLocalRollback, getAgent, getLocator, getUpdateCount, incrementUpdateCount, isLayerBStreamingPossible, isLocator, listenToUnitOfWork, materializeStream, setSqlLength, sqlLength, willBeLayerBStreamed
-
Field Details
-
binaryString_
byte[] binaryString_ -
binaryStream_
InputStream binaryStream_ -
dataOffset_
int dataOffset_
-
-
Constructor Details
-
ClientBlob
-
ClientBlob
ClientBlob(Agent agent, InputStream binaryStream, int length) -
ClientBlob
ClientBlob(Agent agent, InputStream binaryStream) Create a newBlobfrom a stream with unknown length. Important: This constructor is a temporary solution for implementing lengthless overloads in the JDBC4 API. Before a proper solution can be implemented, we need to enable streaming without having to know the stream length in the DRDA protocol. See Jira DERBY-1471 and DERBY-1417 for more details. Shortcomings: This constructor will cause the whole stream to be materialized to determine its length. If the stream is big enough, the client will fail with an OutOfMemoryError. Since this is a temporary solution, state checking is not added to all methods as it would clutter up the class severely. After using the constructor, thelength-method must be called, which will materialize the stream and determine the length. Do not pass a Blob object created with this constructor to the user!- Parameters:
agent-binaryStream- the stream to get data from
-
ClientBlob
Create aBlobobject for a Blob value stored on the server and indentified bylocator.- Parameters:
agent- context for this Blob object (incl. connection)locator- reference id to Blob value on server
-
-
Method Details
-
length
- Specified by:
lengthin interfaceBlob- Specified by:
lengthin classLob- Throws:
SQLException
-
getLocatorLength
Get the length in bytes of theBlobvalue represented by this locator basedobject. A stored procedure call will be made to get it from the server. - Overrides:
getLocatorLengthin classLob- Returns:
- length of Blob in bytes
- Throws:
SqlException
-
getBytes
Returns as an array of bytes part or all of theBLOBvalue that thisBlobobject designates. The byte array contains up tolengthconsecutive bytes starting at positionpos. The starting position must be between 1 and the length of the BLOB plus 1. This allows for zero-length BLOB values, from which only zero-length byte arrays can be returned. If a larger length is requested than there are bytes available, characters from the start position to the end of the BLOB are returned.- 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- is 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 positionstartPos. - Throws:
SQLException- if there is an error accessing theBLOBNOTE: If the starting position is the length of the BLOB plus 1, zero bytess are returned regardless of the length requested.
-
getBytesX
- Throws:
SqlException
-
getBinaryStream
- Specified by:
getBinaryStreamin interfaceBlob- Throws:
SQLException
-
getBinaryStreamX
- Throws:
SqlException
-
position
- Specified by:
positionin interfaceBlob- Throws:
SQLException
-
positionX
- Throws:
SqlException
-
position
- Specified by:
positionin interfaceBlob- Throws:
SQLException
-
positionX
- Throws:
SqlException
-
setBytes
- Specified by:
setBytesin interfaceBlob- Throws:
SQLException
-
setBytes
- Specified by:
setBytesin interfaceBlob- Throws:
SQLException
-
setBytesX
- Throws:
SqlException
-
setBinaryStream
- Specified by:
setBinaryStreamin interfaceBlob- Throws:
SQLException
-
truncate
- Specified by:
truncatein interfaceBlob- Throws:
SQLException
-
free
This method frees theBlobobject and releases the resources that it holds. The object is invalid once thefreemethod is called. Iffreeis called multiple times, the subsequent calls tofreeare treated as a no-op.- Specified by:
freein interfaceBlob- Throws:
SQLException- if an error occurs releasing the Blob's resources
-
getBinaryStream
Returns anInputStreamobject that contains a partialBlobvalue, starting with the byte specified by pos, which is length bytes in length.- Specified by:
getBinaryStreamin interfaceBlob- Parameters:
pos- the offset to the first byte of the partial value to be retrieved. The first byte in theBlobis at position 1.length- the length in bytes of the partial value to be retrieved- Returns:
InputStreamthrough which the partialBlobvalue can be read.- Throws:
SQLException- if pos is less than 1 or if pos is greater than the number of bytes in theBlobor ifpos + lengthis greater thanBlob.length() +1
-
isBinaryString
public boolean isBinaryString() -
isBinaryStream
public boolean isBinaryStream() -
binaryStringPosition
private long binaryStringPosition(byte[] pattern, long start) -
isSubString
private boolean isSubString(byte[] pattern, int index) -
materializeStream
Materialize the stream used for input to the database.- Specified by:
materializeStreamin classLob- Throws:
SqlException
-