com.ibm.as400.access
Class AS400JDBCBlobLocator
- java.lang.Object
-
- com.ibm.as400.access.AS400JDBCBlobLocator
-
- All Implemented Interfaces:
- java.sql.Blob
public class AS400JDBCBlobLocator extends java.lang.Object implements java.sql.Blob
The AS400JDBCBlobLocator class provides access to binary large objects. The data is valid only within the current transaction.
-
-
Method Summary
Methods Modifier and Type Method and Description void
free()
This method frees theBlob
object and releases the resources that it holds.java.io.InputStream
getBinaryStream()
Returns the entire BLOB as a stream of uninterpreted bytes.java.io.InputStream
getBinaryStream(long pos, long length)
Returns anInputStream
object that contains a partialBlob
value, starting with the byte specified by pos, which is length bytes in length.byte[]
getBytes(long position, int length)
Returns part of the contents of the BLOB.int
getHandle()
Returns the handle to this BLOB locator in the database.int
getLocator()
Get the locator handle corresponding to this ClobLocatorlong
length()
Returns the length of the BLOB.long
position(java.sql.Blob pattern, long position)
Returns the position at which a pattern is found in the BLOB.long
position(byte[] pattern, long position)
Returns the position at which a pattern is found in the BLOB.java.io.OutputStream
setBinaryStream(long position)
Returns a stream that an application can use to write to this BLOB.int
setBytes(long position, byte[] bytesToWrite)
Writes an array of bytes to this BLOB, starting at position position in the BLOB.int
setBytes(long position, byte[] bytesToWrite, int offset, int lengthOfWrite)
Writes all or part of the byte array the application passes in to this BLOB, starting at position position in the BLOB.void
truncate(long lengthOfBLOB)
Truncates this BLOB to a length of lengthOfBLOB bytes.
-
-
-
Method Detail
-
getBinaryStream
public java.io.InputStream getBinaryStream() throws java.sql.SQLException
Returns the entire BLOB as a stream of uninterpreted bytes.- Specified by:
getBinaryStream
in interfacejava.sql.Blob
- Returns:
- The stream.
- Throws:
java.sql.SQLException
- If an error occurs.
-
getBytes
public byte[] getBytes(long position, int length) throws java.sql.SQLException
Returns part of the contents of the BLOB.- Specified by:
getBytes
in interfacejava.sql.Blob
- Parameters:
position
- The position within the BLOB (1-based).length
- The length to return.- Returns:
- The contents.
- Throws:
java.sql.SQLException
- If the position is not valid, if the length is not valid, or an error occurs.
-
getHandle
public int getHandle() throws java.sql.SQLException
Returns the handle to this BLOB locator in the database.- Returns:
- The handle to this locator in the database.
- Throws:
java.sql.SQLException
- If a database error occurs.
-
length
public long length() throws java.sql.SQLException
Returns the length of the BLOB.- Specified by:
length
in interfacejava.sql.Blob
- Returns:
- The length of the BLOB, in bytes.
- Throws:
java.sql.SQLException
- If an error occurs.
-
position
public long position(byte[] pattern, long position) throws java.sql.SQLException
Returns the position at which a pattern is found in the BLOB.- Specified by:
position
in interfacejava.sql.Blob
- Parameters:
pattern
- The pattern.position
- The position within the BLOB to begin searching (1-based).- Returns:
- The offset into the BLOB at which the pattern was found, or -1 if the pattern was not found or the pattern was a byte array of length 0.
- Throws:
java.sql.SQLException
- If the position is not valid or an error occurs.
-
position
public long position(java.sql.Blob pattern, long position) throws java.sql.SQLException
Returns the position at which a pattern is found in the BLOB.- Specified by:
position
in interfacejava.sql.Blob
- Parameters:
pattern
- The pattern.position
- The position within the BLOB to begin searching (1-based).- Returns:
- The offset into the BLOB at which the pattern was found, or -1 if the pattern was not found or the pattern was a byte array of length 0.
- Throws:
java.sql.SQLException
- If the position is not valid or an error occurs.
-
setBinaryStream
public java.io.OutputStream setBinaryStream(long position) throws java.sql.SQLException
Returns a stream that an application can use to write to this BLOB. The stream begins at position position.- Specified by:
setBinaryStream
in interfacejava.sql.Blob
- Parameters:
position
- The position (1-based) in the BLOB where writes should start.- Returns:
- An OutputStream object to which data can be written by an application.
- Throws:
java.sql.SQLException
- If there is an error accessing the BLOB or if the position specified is greater than the length of the BLOB.
-
setBytes
public int setBytes(long position, byte[] bytesToWrite) throws java.sql.SQLException
Writes an array of bytes to this BLOB, starting at position position in the BLOB.- Specified by:
setBytes
in interfacejava.sql.Blob
- Parameters:
position
- The position (1-based) in the BLOB where writes should start.bytesToWrite
- The array of bytes to be written to this BLOB.- Returns:
- The number of bytes written to the BLOB.
- Throws:
java.sql.SQLException
- If there is an error accessing the BLOB or if the position specified is greater than the length of the BLOB.
-
setBytes
public int setBytes(long position, byte[] bytesToWrite, int offset, int lengthOfWrite) throws java.sql.SQLException
Writes all or part of the byte array the application passes in to this BLOB, starting at position position in the BLOB. The lengthOfWrite bytes written will start from offset in the bytes that were provided by the application.- Specified by:
setBytes
in interfacejava.sql.Blob
- Parameters:
position
- The position (1-based) in the BLOB where writes should start.bytesToWrite
- The array of bytes to be written to this BLOB.offset
- The offset into the array at which to start reading bytes (0-based).lengthOfWrite
- The number of bytes to be written to the BLOB from the array of bytes.- Returns:
- The number of bytes written.
- Throws:
java.sql.SQLException
- If there is an error accessing the BLOB or if the position specified is greater than the length of the BLOB.
-
truncate
public void truncate(long lengthOfBLOB) throws java.sql.SQLException
Truncates this BLOB to a length of lengthOfBLOB bytes.- Specified by:
truncate
in interfacejava.sql.Blob
- Parameters:
lengthOfBLOB
- The length, in bytes, that this BLOB should be after truncation.- Throws:
java.sql.SQLException
- If there is an error accessing the BLOB or if the length specified is greater than the length of the BLOB.
-
free
public void free() throws java.sql.SQLException
This method frees theBlob
object and releases the resources that it holds. The object is invalid once thefree
method is called. Iffree
is called multiple times, the subsequent calls tofree
are treated as a no-op.- Specified by:
free
in interfacejava.sql.Blob
- Throws:
java.sql.SQLException
- If a database error occurs. if an error occurs releasing the Blob's resources
-
getBinaryStream
public java.io.InputStream getBinaryStream(long pos, long length) throws java.sql.SQLException
Returns anInputStream
object that contains a partialBlob
value, starting with the byte specified by pos, which is length bytes in length.- Specified by:
getBinaryStream
in interfacejava.sql.Blob
- Parameters:
pos
- the offset to the first byte of the partial value to be retrieved. The first byte in theBlob
is at position 1length
- the length in bytes of the partial value to be retrieved- Returns:
InputStream
through which the partialBlob
value can be read.- Throws:
java.sql.SQLException
- If a database error occurs. if pos is less than 1 or if pos is greater than the number of bytes in theBlob
or if pos + length is greater than the number of bytes in theBlob
-
getLocator
public int getLocator()
Get the locator handle corresponding to this ClobLocator- Returns:
- locator handle
-
-