I need to write Byte Array
value into Cassandra using Java code. Then I will be having my C++ program to read that same Byte Array
data from Cassandra.
That Byte Array is made up of three Byte Arrays as described below -
short schemaId = 32767;
long lastModifiedDate = "1379811105109L";
byte[] avroBinaryValue = os.toByteArray();
Now, I will write schemaId
, lastModifiedDate
and avroBinaryValue
together into a single Byte Array
and that resulting Byte Array, I will write back into Cassandra and then I will be having my C++ program which will retrieve that Byte Array data from Cassandra and then deserialize it to extract schemaId
, lastModifiedDate
and avroBinaryValue
from it.
So now I am confuse whether I should be using Big Endian here in my Java code while writing to Cassandra? Or small Endian Byte Order here while storing the data into Cassandra?
Below is the code, I have got so far in Java which will serialize everything into a Single Byte Array...
public static void main(String[] args) throws Exception {
String os = "whatever os is";
byte[] avroBinaryValue = os.getBytes();
long lastModifiedDate = 1379811105109L;
short schemaId = 32767;
ByteArrayOutputStream byteOsTest = new ByteArrayOutputStream();
DataOutputStream outTest = new DataOutputStream(byteOsTest);
outTest.writeShort(schemaId); // first write schemaId
outTest.writeLong(lastModifiedDate); // second lastModifiedDate
outTest.writeInt(avroBinaryValue.length); // then attributeLength
outTest.write(avroBinaryValue); // then its value
byte[] allWrittenBytesTest = byteOsTest.toByteArray();
// write this allWrittenBytesTest into Cassandra
// now deserialize it and extract everything from it
DataInputStream inTest = new DataInputStream(new ByteArrayInputStream(allWrittenBytesTest));
short schemaIdTest = inTest.readShort();
long lastModifiedDateTest = inTest.readLong();
int sizeAvroTest = inTest.readInt();
byte[] avroBinaryValue1 = new byte[sizeAvroTest];
inTest.read(avroBinaryValue1, 0, sizeAvroTest);
System.out.println(schemaIdTest);
System.out.println(lastModifiedDateTest);
System.out.println(new String(avroBinaryValue1));
}
And I am also trying to see whether there is any efficient or proper way of doing this in Java as I need to retrieve this data from Cassandra using C++ program so I don't want to have any problem on C++ side as well.. So I am trying to make sure when I am writing this data to Cassandra from Java side, everything looks good..
Right now, for testing what I was doing is- I was writing this Byte Array into a file from Java program and I am reading that same file using C++ program and then deserializing that Byte Array accordingly..
I hope my question is clear enough.. Can anybody help me with this?