Package org.mariadb.jdbc
Class MariaDbBlob
java.lang.Object
org.mariadb.jdbc.MariaDbBlob
- All Implemented Interfaces:
Serializable,Blob
- Direct Known Subclasses:
MariaDbClob
MariaDB Blob implementation
- See Also:
-
Field Summary
Fields -
Constructor Summary
ConstructorsConstructorDescriptionCreates an empty blob.MariaDbBlob(byte[] bytes) Creates a blob with content.MariaDbBlob(byte[] bytes, int offset, int length) Creates a blob with content. -
Method Summary
Modifier and TypeMethodDescriptionbooleanvoidfree()This method frees theBlobobject and releases the resources that it holds.Retrieves theBLOBvalue designated by thisBlobinstance as a stream.getBinaryStream(long pos, long length) Returns anInputStreamobject that contains a partialBlobvalue, starting with the byte specified by pos, which is length bytes in length.byte[]getBytes(long pos, int length) Retrieves all or part of theBLOBvalue that thisBlobobject represents, as an array of bytes.inthashCode()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.static MariaDbBlobsafeMariaDbBlob(byte[] bytes, int offset, int length) Return a new Blob from blob datasetBinaryStream(long pos) Retrieves a stream that can be used to write to theBLOBvalue that thisBlobobject represents.intsetBytes(long pos, byte[] bytes) Writes the given array of bytes to theBLOBvalue that thisBlobobject represents, starting at positionpos, and returns the number of bytes written.intsetBytes(long pos, byte[] bytes, int offset, int len) Writes all or part of the givenbytearray to theBLOBvalue that thisBlobobject represents and returns the number of bytes written.voidtruncate(long len) Truncates theBLOBvalue that thisBlobobject represents to belenbytes in length.
-
Field Details
-
data
protected byte[] datacontent -
offset
protected transient int offsetdata offset -
length
protected transient int lengthdata length
-
-
Constructor Details
-
MariaDbBlob
public MariaDbBlob()Creates an empty blob. -
MariaDbBlob
public MariaDbBlob(byte[] bytes) Creates a blob with content.- Parameters:
bytes- the content for the blob.
-
MariaDbBlob
public MariaDbBlob(byte[] bytes, int offset, int length) Creates a blob with content.- Parameters:
bytes- the content for the blob.offset- offsetlength- length
-
-
Method Details
-
safeMariaDbBlob
Return a new Blob from blob data- Parameters:
bytes- dataoffset- data offsetlength- data length- Returns:
- new Blob
-
length
public long length()Returns the number of bytes in theBLOBvalue designated by thisBlobobject. -
getBytes
Retrieves all or part of theBLOBvalue that thisBlobobject represents, as an array of bytes. Thisbytearray contains up tolengthconsecutive bytes starting at positionpos.- 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; the value for length must be 0 or greater- 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; if pos is less than 1 or length is less than 0- Since:
- 1.2
- See Also:
-
getBinaryStream
Retrieves theBLOBvalue designated by thisBlobinstance as a stream.- Specified by:
getBinaryStreamin interfaceBlob- Returns:
- a stream containing the
BLOBdata - Throws:
SQLException- if something went wrong- See Also:
-
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 1length- 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 if pos + length is greater than the number of bytes in theBlob
-
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
-
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
-
setBytes
Writes the given array of bytes to theBLOBvalue that thisBlobobject represents, starting at positionpos, and returns the number of bytes written. The array of bytes will overwrite the existing bytes in theBlobobject starting at the positionpos. If the end of theBlobvalue is reached while writing the array of bytes, then the length of theBlobvalue will be increased to accommodate the extra bytes.- Specified by:
setBytesin interfaceBlob- Parameters:
pos- the position in theBLOBobject at which to start writing; the first position is 1bytes- the array of bytes to be written to theBLOBvalue that thisBlobobject represents- Returns:
- the number of bytes written
- Throws:
SQLException- See Also:
-
setBytes
Writes all or part of the givenbytearray to theBLOBvalue that thisBlobobject represents and returns the number of bytes written. Writing starts at positionposin theBLOBvalue;lenbytes from the given byte array are written. The array of bytes will overwrite the existing bytes in theBlobobject starting at the positionpos. If the end of theBlobvalue is reached while writing the array of bytes, then the length of theBlobvalue will be increased to accommodate the extra bytes.Note: If the value specified for
posis greater than the length+1 of theBLOBvalue then the behavior is undefined. Some JDBC drivers may throw aSQLExceptionwhile other drivers may support this operation.- Specified by:
setBytesin interfaceBlob- Parameters:
pos- the position in theBLOBobject at which to start writing; the first position is 1bytes- the array of bytes to be written to thisBLOBobjectoffset- the offset into the arraybytesat which to start reading the bytes to be setlen- the number of bytes to be written to theBLOBvalue from the array of bytesbytes- Returns:
- the number of bytes written
- Throws:
SQLException- if there is an error accessing theBLOBvalue or if pos is less than 1- See Also:
-
setBinaryStream
Retrieves a stream that can be used to write to theBLOBvalue that thisBlobobject represents. The stream begins at positionpos. The bytes written to the stream will overwrite the existing bytes in theBlobobject starting at the positionpos. If the end of theBlobvalue is reached while writing to the stream, then the length of theBlobvalue will be increased to accommodate the extra bytes.Note: If the value specified for
posis greater than the length+1 of theBLOBvalue then the behavior is undefined. Some JDBC drivers may throw aSQLExceptionwhile other drivers may support this operation.- Specified by:
setBinaryStreamin interfaceBlob- Parameters:
pos- the position in theBLOBvalue at which to start writing; the first position is 1- Returns:
- a
java.io.OutputStreamobject to which data can be written - Throws:
SQLException- if there is an error accessing theBLOBvalue or if pos is less than 1- Since:
- 1.4
- See Also:
-
truncate
public void truncate(long len) Truncates theBLOBvalue that thisBlobobject represents to belenbytes in length. -
free
public void free()This method frees theBlobobject and releases the resources that it holds. The object is invalid once thefreemethod is called.After
freehas been called, any attempt to invoke a method other thanfreewill result in aSQLExceptionbeing thrown. Iffreeis called multiple times, the subsequent calls tofreeare treated as a no-op. -
equals
-
hashCode
public int hashCode()
-