Package org.mariadb.jdbc
Class MariaDbBlob
- java.lang.Object
-
- org.mariadb.jdbc.MariaDbBlob
-
- All Implemented Interfaces:
java.io.Serializable,java.sql.Blob
- Direct Known Subclasses:
MariaDbClob
public class MariaDbBlob extends java.lang.Object implements java.sql.Blob, java.io.SerializableMariaDB Blob implementation- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) static classMariaDbBlob.BlobOutputStream
-
Field Summary
Fields Modifier and Type Field Description protected byte[]datacontentprotected intlengthdata lengthprotected intoffsetdata offsetprivate static longserialVersionUID
-
Constructor Summary
Constructors Modifier Constructor Description MariaDbBlob()Creates an empty blob.MariaDbBlob(byte[] bytes)Creates a blob with content.MariaDbBlob(byte[] bytes, int offset, int length)Creates a blob with content.privateMariaDbBlob(int offset, int length, byte[] bytes)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanequals(java.lang.Object o)voidfree()This method frees theBlobobject and releases the resources that it holds.java.io.InputStreamgetBinaryStream()Retrieves theBLOBvalue designated by thisBlobinstance as a stream.java.io.InputStreamgetBinaryStream(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.longposition(java.sql.Blob pattern, long start)Retrieves the byte position in theBLOBvalue designated by thisBlobobject at whichpatternbegins.static MariaDbBlobsafeMariaDbBlob(byte[] bytes, int offset, int length)Return a new Blob from blob datajava.io.OutputStreamsetBinaryStream(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 Detail
-
serialVersionUID
private static final long serialVersionUID
- See Also:
- Constant Field Values
-
data
protected byte[] data
content
-
offset
protected transient int offset
data offset
-
length
protected transient int length
data length
-
-
Constructor Detail
-
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
-
MariaDbBlob
private MariaDbBlob(int offset, int length, byte[] bytes)
-
-
Method Detail
-
safeMariaDbBlob
public static MariaDbBlob safeMariaDbBlob(byte[] bytes, int offset, int length)
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.- Specified by:
lengthin interfacejava.sql.Blob- Returns:
- length of the
BLOBin bytes
-
getBytes
public byte[] getBytes(long pos, int length) throws java.sql.SQLExceptionRetrieves all or part of theBLOBvalue that thisBlobobject represents, as an array of bytes. Thisbytearray contains up tolengthconsecutive bytes starting at positionpos.- Specified by:
getBytesin interfacejava.sql.Blob- 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:
java.sql.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:
setBytes(long, byte[])
-
getBinaryStream
public java.io.InputStream getBinaryStream() throws java.sql.SQLExceptionRetrieves theBLOBvalue designated by thisBlobinstance as a stream.- Specified by:
getBinaryStreamin interfacejava.sql.Blob- Returns:
- a stream containing the
BLOBdata - Throws:
java.sql.SQLException- if something went wrong- See Also:
setBinaryStream(long)
-
getBinaryStream
public java.io.InputStream getBinaryStream(long pos, long length) throws java.sql.SQLExceptionReturns anInputStreamobject that contains a partialBlobvalue, starting with the byte specified by pos, which is length bytes in length.- Specified by:
getBinaryStreamin interfacejava.sql.Blob- 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:
java.sql.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
public long position(byte[] pattern, long start) throws java.sql.SQLExceptionRetrieves the byte position at which the specified byte arraypatternbegins within theBLOBvalue that thisBlobobject represents. The search forpatternbegins at positionstart.- Specified by:
positionin interfacejava.sql.Blob- 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:
java.sql.SQLException
-
position
public long position(java.sql.Blob pattern, long start) throws java.sql.SQLExceptionRetrieves the byte position in theBLOBvalue designated by thisBlobobject at whichpatternbegins. The search begins at positionstart.- Specified by:
positionin interfacejava.sql.Blob- 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:
java.sql.SQLException
-
setBytes
public int setBytes(long pos, byte[] bytes) throws java.sql.SQLExceptionWrites 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 interfacejava.sql.Blob- 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:
java.sql.SQLException- See Also:
getBytes(long, int)
-
setBytes
public int setBytes(long pos, byte[] bytes, int offset, int len) throws java.sql.SQLExceptionWrites 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 interfacejava.sql.Blob- 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:
java.sql.SQLException- if there is an error accessing theBLOBvalue or if pos is less than 1- See Also:
getBytes(long, int)
-
setBinaryStream
public java.io.OutputStream setBinaryStream(long pos) throws java.sql.SQLExceptionRetrieves 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 interfacejava.sql.Blob- 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:
java.sql.SQLException- if there is an error accessing theBLOBvalue or if pos is less than 1- Since:
- 1.4
- See Also:
getBinaryStream()
-
truncate
public void truncate(long len)
Truncates theBLOBvalue that thisBlobobject represents to belenbytes in length.- Specified by:
truncatein interfacejava.sql.Blob- Parameters:
len- the length, in bytes, to which theBLOBvalue that thisBlobobject represents should be truncated
-
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.- Specified by:
freein interfacejava.sql.Blob
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
-