Convert IfxLocator to a hexadecimal string

Some applications, for example, web browsers, can only process ASCII data; they require IfxLocator to be converted to hexadecimal string format. In a typical web-based application, the web server queries the database table and sends the results to the browser. Instead of sending the entire smart large object, the web server converts the locator into hexadecimal string format and sends it to the browser. If the user requests the browser to display the smart large object, the browser sends the locator in hexadecimal format back to the web server. The web server then reconstructs the binary locator from the hexadecimal string and sends the corresponding smart large object data to the browser.

To convert between the IfxLocator byte array and a hexadecimal number, use the methods listed in the following table.
Task performed Method signature Additional information
Converts a byte array to a hexadecimal character string public static String toHexString( byte[] byteBuf); Works on data other than IfxLocator Provided in the com.informix.util.stringUtil class
Converts a hexadecimal character string to a byte array public static byte[] fromHexString( String str) throws NumberFormatException; Works on data other than IfxLocator Provided in the com.informix.util.stringUtil class
Constructs an IfxLocator object using a byte array public IfxLocator(byte[] byteBuf) throws SQLException; Provided in the IfxLocator class
Converts an IfxLocator byte array to a hexadecimal character string public String toString(); Provided in the IfxLocator class
Converts a hexadecimal character string to an IfxLocator byte array public byte[] toBytes(); Provided in the IfxLocator class
The following example uses the toString() and toBytes() methods to fetch the locator from a smart large object and then convert it into a hexadecimal string:
...

String hexLoc = "";
byte[] blobBytes;
byte[] rawLocA = null;
IfxLocator loc;
try
{
     ResultSet rs = stmt.executeQuery("select b1 from btab");
     while(rs.next())
     {
         IfxBblob b=(IfxBblob)rs.getBlob(1);
         loc =b.getLocator();
         hexLoc = loc.toString();
         rawLocA = loc.toBytes();
     }
}
catch(SQLException e)
{}
The following example uses the IfxLocator() method to construct an IfxLocator, which is then used to read a smart large object:
...

try
{
     IfxLocator loc2 = new IfxLocator(rawLoc);
     IfxSmartBlob b2 = new IfxSmartBlob((IfxConnection)myConn);
     int lofd = b2.IfxLoOpen(loc2, b2.LO_RDWR);
     blobBytes = b2.IfxLoRead(lofd, fileLength);
}
catch(SQLException e)
  {}