Read data from a smart large object

You can read data from a smart large object in the following ways:
  • Read the data from the object into a byte[ ] buffer.
  • Read the data from the object into a file output stream.
  • Read the data from the object into a file.
Use the IfxLoRead() method in the IfxSmartBlob class, which has the following signatures, to read from a smart large object into a buffer or file output stream:
public byte[] IfxLoRead(int lofd, int nbytes) throws SQLException
public int IfxLoRead(int lofd, byte[] buffer, int nbytes) throws 
   SQLException
public int IfxLoRead(int lofd, FileOutputStream fout, int nbytes
   throws SQLException
public int IfxLoRead(int lofd, byte[] buffer, int nbytes, int 
   offset throws SQLException

The lofd parameter is a locator file descriptor returned by the IfxLoRead() or IfxLoOpen() method.

The first version returns nbytes bytes of data into a byte buffer. This version of the method allocates the memory for the buffer. The second version reads nbytes bytes of data into an already allocated buffer. The third version reads nbytes bytes of data into a file output stream. The fourth version reads nbytes bytes of data into a byte buffer starting at the current seek position plus offset into the smart large object. The return values for the last three versions indicate the number of bytes read.

Use the IfxLoToFile() method in the IfxSmartBlob class, which has the following signatures, to read from a smart large object into a file:
public int IfxLoToFile(IfxLocator loPtr, String filename, int flag 
   , int whence) throws SQLException
public int IfxLoToFile(IfxBblob blob, String filename, int flag , 
   int whence) throws SQLException
public int IfxLoToFile(IfxCblob clob, String filename, int flag , 
   int whence) throws SQLException

The first version reads the smart large object that is referenced by the locator pointer loPtr. The second and third versions read the smart large objects that are referenced by the specified IfxBblob and IfxCblob objects, respectively.

The flag parameter indicates whether the file is on the client or the server. The value is either IfxSmartBlob.LO_CLIENT_FILE or IfxSmartBlob.LO_SERVER_FILE. The whence parameter identifies the starting seek position. For the values, see Position within a smart large object.

Tip: There has been a change in the signature of the following function:
IfxSmartBlob.IfxLoToFile().
This function used to accept four parameters, but now only accepts three parameters. All three overloaded functions for IfxLoToFile() accept three parameters.