final class EmbedBlob extends ConnectionChild implements java.sql.Blob, EngineLOB
Supports
Modifier and Type | Field and Description |
---|---|
private LOBStreamControl |
control |
private boolean |
isValid |
private int |
locator
Locator value for this Blob, used as a handle by the client driver to
map operations to the correct Blob on the server side.
|
private boolean |
materialized
Tells whether the Blob has been materialized or not.
|
private PositionedStoreStream |
myStream
The underlying positionable store stream, if any.
|
private long |
streamLength
Length of the stream representing the Blob.
|
private int |
streamPositionOffset
Position offset for the stream representing the Blob, if any.
|
factory, localConn
Modifier | Constructor and Description |
---|---|
(package private) |
EmbedBlob(byte[] blobBytes,
EmbedConnection con)
This constructor is used to create a empty Blob object.
|
protected |
EmbedBlob(DataValueDescriptor dvd,
EmbedConnection con) |
Modifier and Type | Method and Description |
---|---|
private boolean |
checkMatch(java.sql.Blob pattern,
long pos)
Checks if the pattern (starting from the second byte) appears inside
the Blob content.
|
private boolean |
checkMatch(byte[] pattern,
long pos)
Checks if the pattern (starting from the second byte) appears inside
the Blob content.
|
private void |
checkValidity() |
protected void |
finalize() |
void |
free()
This method frees the
Blob object and releases the resources that
it holds. |
java.io.InputStream |
getBinaryStream()
Retrieves the
BLOB designated by this
Blob instance as a stream. |
java.io.InputStream |
getBinaryStream(long pos,
long length)
Returns an
InputStream object that contains a partial
Blob value, starting with the byte specified by pos,
which is length bytes in length. |
byte[] |
getBytes(long startPos,
int length)
Returns as an array of bytes part or all of the
BLOB
value that this Blob object designates. |
int |
getLocator()
Return locator for this lob.
|
private java.sql.SQLException |
handleMyExceptions(java.lang.Throwable t) |
private int |
handleStreamValue(java.io.InputStream dvdStream,
EmbedConnection con)
Constructs a Blob object on top of a stream.
|
(package private) boolean |
isMaterialized()
Returns if blob data is stored locally (using LOBStreamControl).
|
long |
length()
Returns the number of bytes in the
BLOB value
designated by this Blob object. |
long |
position(java.sql.Blob pattern,
long start)
Determines the byte position in the
BLOB value
designated by this Blob object at which
pattern begins. |
long |
position(byte[] pattern,
long start)
Determines the byte position at which the specified byte
pattern begins within the BLOB
value that this Blob object represents. |
private int |
read(long pos)
Reads one byte from the Blob at the specified position.
|
java.io.OutputStream |
setBinaryStream(long pos)
JDBC 3.0
Retrieves a stream that can be used to write to the BLOB value that this
Blob object represents.
|
private long |
setBlobPosition(long logicalPos)
Sets the position of the Blob to
logicalPos , where position 0 is
the beginning of the Blob content. |
int |
setBytes(long pos,
byte[] bytes)
Writes the given array of bytes to the BLOB value that this Blob object
represents, starting at position pos, and returns the number of bytes
written.
|
int |
setBytes(long pos,
byte[] bytes,
int offset,
int len)
Writes all or part of the given array of byte array to the BLOB value
that this Blob object represents and returns the number of bytes written.
|
void |
truncate(long len)
JDBC 3.0
Truncates the BLOB value that this Blob object represents to be len bytes
in length.
|
commitIfAutoCommit, commitIfNeeded, getCal, getConnectionSynchronization, getEmbedConnection, getLanguageConnectionContext, getLCC, handleException, needCommit, newSQLException, restoreContextStack, restoreIntrFlagIfSeen, setupContextStack
private boolean materialized
Materialization happens when the Blob is updated by the user. A materialized Blob is represented either in memory or in a temporary file on disk, depending on size.
A Blob that has not been materialized is represented by a stream into the Derby store, and is read-only.
private PositionedStoreStream myStream
If materialized
is true
, the stream is null
.
private int locator
getLocator()
private long streamLength
Set to -1 when the stream has been materialized
or
the length of the stream is not currently known.
private final int streamPositionOffset
This offset accounts for the bytes encoding the stream length at the
head of the stream. Data byte pos
is at
pos + streamPositionOffset
in the underlying stream.
Set to Integer.MIN_VALUE
if the Blob isn't represented by a
store stream.
private boolean isValid
private LOBStreamControl control
EmbedBlob(byte[] blobBytes, EmbedConnection con) throws java.sql.SQLException
blobBytes
- A byte array containing the data to be stores in the
Blob.con
- The EmbedConnection object associated with this Blob object.java.sql.SQLException
protected EmbedBlob(DataValueDescriptor dvd, EmbedConnection con) throws StandardException, java.sql.SQLException
StandardException
java.sql.SQLException
private int handleStreamValue(java.io.InputStream dvdStream, EmbedConnection con) throws StandardException, java.sql.SQLException
dvdStream
- the source streamcon
- the connection owning the BlobStandardException
- if accessing the stream fails, or if writing
data to temporary storage failsjava.sql.SQLException
private long setBlobPosition(long logicalPos) throws StandardException, java.io.IOException
logicalPos
, where position 0 is
the beginning of the Blob content.
The position is only guaranteed to be valid from the time this method is invoked until the synchronization monitor is released, or until the next invokation of this method.
The position is logical in the sense that it specifies the requested position in the Blob content. This position might be at a different position in the underlying representation, for instance the Derby store stream prepends the Blob content with a length field.
logicalPos
- requested Blob position, 0-basedjava.io.IOException
- if reading/accessing the Blob failsStandardException
- throws BLOB_POSITION_TOO_LARGE if the requested
position is larger than the Blob length, throws other SQL states if
resetting the stream failsprivate int read(long pos) throws java.io.IOException, StandardException
Depending on the representation, this might result in a read from a byte array, a temporary file on disk or from a Derby store stream.
java.io.IOException
- if reading from the underlying data representation
failsStandardException
public long length() throws java.sql.SQLException
BLOB
value
designated by this Blob
object.length
in interface java.sql.Blob
BLOB
in bytesjava.sql.SQLException
- if there is an error accessing the
length of the BLOB
public byte[] getBytes(long startPos, int length) throws java.sql.SQLException
BLOB
value that this Blob
object designates. The byte
array contains up to length
consecutive bytes
starting at position startPos
.
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.getBytes
in interface java.sql.Blob
startPos
- the ordinal position of the first byte in the
BLOB
value to be extracted; the first byte is at
position 1length
- is the number of consecutive bytes to be copiedlength
consecutive bytes from the BLOB
value designated
by this Blob
object, starting with the
byte at position startPos
.java.sql.SQLException
- if there is an error accessing the
BLOB
NOTE: If the starting position is the length of the BLOB plus 1,
zero bytess are returned regardless of the length requested.public java.io.InputStream getBinaryStream() throws java.sql.SQLException
BLOB
designated by this
Blob
instance as a stream.getBinaryStream
in interface java.sql.Blob
BLOB
datajava.sql.SQLException
- if there is an error accessing the
BLOB
public long position(byte[] pattern, long start) throws java.sql.SQLException
pattern
begins within the BLOB
value that this Blob
object represents. The
search for pattern
. begins at position
start
position
in interface java.sql.Blob
pattern
- the byte array for which to searchstart
- the position at which to begin searching; the
first position is 1java.sql.SQLException
- if there is an error accessing the
BLOB
private boolean checkMatch(byte[] pattern, long pos) throws java.io.IOException, StandardException
At this point, the first byte of the pattern must already have been
matched, and pos
must be pointing at the second byte to compare.
pattern
- the byte array to search for, passed in by the userpos
- the position in the Blob content to start searching fromtrue
if a match is found, false
if not.java.io.IOException
StandardException
public long position(java.sql.Blob pattern, long start) throws java.sql.SQLException
BLOB
value
designated by this Blob
object at which
pattern
begins. The search begins at position
start
.position
in interface java.sql.Blob
pattern
- the Blob
object designating
the BLOB
value for which to searchstart
- the position in the BLOB
value
at which to begin searching; the first position is 1java.sql.SQLException
- if there is an error accessing the
BLOB
private boolean checkMatch(java.sql.Blob pattern, long pos) throws java.io.IOException, StandardException
pattern
- the Blob to search for, passed in by the userpos
- the position in the Blob (this) content to start searchingtrue
if a match is found, false
if not.java.io.IOException
StandardException
private java.sql.SQLException handleMyExceptions(java.lang.Throwable t) throws java.sql.SQLException
java.sql.SQLException
protected void finalize()
finalize
in class java.lang.Object
public int setBytes(long pos, byte[] bytes) throws java.sql.SQLException
setBytes
in interface java.sql.Blob
pos
- the position in the BLOB object at which to start writingbytes
- the array of bytes to be written to the BLOB value that this
Blob object representsjava.sql.SQLException
- if writing the bytes to the BLOB failspublic int setBytes(long pos, byte[] bytes, int offset, int len) throws java.sql.SQLException
setBytes
in interface java.sql.Blob
pos
- the position in the BLOB object at which to start writingbytes
- the array of bytes to be written to the BLOB value that this
Blob object representsoffset
- the offset into the byte array at which to start reading
the bytes to be writtenlen
- the number of bytes to be written to the BLOB value from the
array of bytes bytesjava.sql.SQLException
- if writing the bytes to the BLOB failsjava.lang.IndexOutOfBoundsException
- if len
is larger than
bytes.length - offset
public java.io.OutputStream setBinaryStream(long pos) throws java.sql.SQLException
setBinaryStream
in interface java.sql.Blob
pos
- - the position in the BLOB object at which to start writingjava.sql.SQLException
- Feature not implemented for now.public void truncate(long len) throws java.sql.SQLException
truncate
in interface java.sql.Blob
len
- - the length, in bytes, to which the BLOB value that this Blob
object represents should be truncatedjava.sql.SQLException
- Feature not implemented for now.public void free() throws java.sql.SQLException
Blob
object and releases the resources that
it holds. The object is invalid once the free
method is called. If free
is called multiple times, the subsequent
calls to free
are treated as a no-op.public java.io.InputStream getBinaryStream(long pos, long length) throws java.sql.SQLException
InputStream
object that contains a partial
Blob
value, starting with the byte specified by pos,
which is length bytes in length.getBinaryStream
in interface java.sql.Blob
pos
- the offset to the first byte of the partial value to be
retrieved. The first byte in the Blob
is at
position 1length
- the length in bytes of the partial value to be retrievedBlob
value can be read.java.sql.SQLException
- if pos is less than 1 or if pos is greater than
the number of bytes in the Blob
or if pos + length
is greater than Blob.length() +1
private void checkValidity() throws java.sql.SQLException
java.sql.SQLException
boolean isMaterialized()
public int getLocator()
getLocator
in interface EngineLOB
Apache Derby V10.13 Internals - Copyright © 2004,2016 The Apache Software Foundation. All Rights Reserved.