Our application stores some bins in the form of Strings. The problem that we are facing is when we are trying to save a record having value of one of the bin as "value=“0x10A5"”, Aerospike is storing the following:
“msTimezone”: “\u0010¥”
It is storing the values by converting it to its Symbol representation … here Yen symbol “¥” signifies A5.
So, when data is fetched from the database and dumped in flat files, these characters are interpreted by our customer as junk characters.
How during the db fetch we can get the correct value ?
import com.aerospike.client.AerospikeException;
import com.aerospike.client.Bin;
import com.aerospike.client.Host;
import com.aerospike.client.Key;
import com.aerospike.client.Record;
import com.aerospike.client.Value;
import com.aerospike.client.policy.ClientPolicy;
import com.aerospike.client.policy.WritePolicy;
public class Aerospike {
public static void main(String[] args)
{
//Get host
Host host = new Host("127.0.0.1",3000);
ClientPolicy clientPolicy = new ClientPolicy();
WritePolicy writePolicy = new WritePolicy();
AerospikeClient client = new AerospikeClient(clientPolicy, host);
Key key = new Key("test", "myset", "mykey");
Bin bin = new Bin("mybin", "\u0010\u00A5");
client.put(writePolicy, key, bin);
//Read the records
Record record = client.get(null, key);
//Print all the record
for(String binKey : record.bins.keySet())
{
System.out.println(binKey+" <-----> "+record.bins.get(binKey));
}
client.close();
}
}
The send/receive bytes are identical ( “\u0010\u00A5”). The yen sign is only being shown when printing the string. The first character is not printable and the second character is the yen sign. See the following code:
String sendValue = "\u0010\u00A5";
int max = sendValue.length();
for (int i = 0; i < max; i++) {
char c = sendValue.charAt(i);
System.out.println("send[" + i + "]=" + (int)c);
}
System.out.println("send string=" + sendValue);
Key key = new Key("test", "myset", "mykey");
Bin bin = new Bin("mybin", sendValue);
client.put(null, key, bin);
Record record = client.get(null, key);
String receiveValue = (String)record.bins.get("mybin");
max = receiveValue.length();
for (int i = 0; i < max; i++) {
char c = receiveValue.charAt(i);
System.out.println("receive[" + i + "]=" + (int)c);
}
System.out.println("receive string=" + sendValue);
if (sendValue.equals(receiveValue)) {
System.out.println("send == receive");
}
else {
System.out.println("send != receive");
}