Kbase 21913: OPEN CLIENT: Convert String Rowid to Rowid Object (Java)
Autor |
  Progress Software Corporation - Progress |
Acesso |
  Público |
Publicação |
  05/04/2002 |
|
SUMMARY:
In Java, the Rowid object that Progress provides does not afford the means to accept a String representation of a 4GL ROWID and convert it back to a valid ROWID to be sent back to the AppServer as an input parameter to some 4GL program. The only method that we currently provide is for you to pass a byte array to the constructor. Unfortunately, the byte array you get from doing a String.getBytes() method call does not give you a byte array that contains the information we need.
SOLUTION:
The following Java method does the required conversion.
public static Rowid convertStringToRowid(String rowidAsString)
{
byte byte0;
byte byte1;
byte[] tempBytes = rowidAsString.getBytes();
byte[] rowidBytes = new byte[(rowidAsString.length() - 2) / 2];
for (int i=2, j=0; i < tempBytes.length; i = i + 2)
{
byte0 = (byte)(((byte)((tempBytes[i] <= 57) ? (tempBytes[i])-48 :
(tempBytes[i])-87)) * 16);
byte1 = (byte)((tempBytes[i+1] <= 57) ? (tempBytes[i+1])-48 :
(tempBytes[i+1])-87);
rowidBytes[j] = (byte) ((byte)byte0 | (byte)byte1);
j++;
}
return new Rowid(rowidBytes);
}