What's a good way to represent and store data in Java's RecordStore?

281 views Asked by At

Given that Java ME allows for no reflection and is quite stripped down, what would a good approach to storing data in a RecordStore be? I thought of devising a JSON-like syntax adapter class which would probably require every class whose values are to be stored to implement a Hashtable + might probably require an additional regex library as even that's been taken away.

If you're wondering why on earth I need it, it's for an assignment. So the dilemma is really between writing a rather unnecessarily large chunk of proper code as a matter of principle or hardcoding everything in knowing nobody has to suffer through maintenance of this junk down the line. But, the good principles person in me is leaning towards the former.

EDIT: I should have elaborated — I'd like to store object's data within the RecordStore, so I'm trying to devise a method to represent an object as a string which can then be converted into a byte array.

1

There are 1 answers

2
funkybro On

For every object you want to save in the RecordStore, pare it down to its component Strings and primitives, then serialise it to a byte array, using a ByteArrayOutputStream wrapped in a DataOutputStream. Then write this byte array to RMS.

Reverse the process using a ByteArrayInputStream wrapped in a DataInputStream to get the object back.