开发者

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

开发者 https://www.devze.com 2022-12-22 14:25 出处:网络
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 wou

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 开发者_如何学Pythonthe 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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号