views:

52

answers:

3

Hi all,

I am making a java program that has a collection of flash-card like objects. I store the objects in a jtree composed of defaultmutabletreenodes. Each node has a user object attached to it with has a few string/native data type parameters. However, i also want each of these objects to have an image (typical formats, jpg, png etc).

I would like to be able to store all of this information, including the images and the tree data to the disk in a single file so the file can be transferred between users and the entire tree, including the images and parameters for each object, can be reconstructed.

I had not approached a problem like this before so I was not sure what the best practices were. I found XLMEncoder (http://java.sun.com/j2se/1.4.2/docs/api/java/beans/XMLEncoder.html) to be a very effective way of storing my tree and the native data type information. However I couldn't figure out how to save the image data itself inside of the XML file, and I'm not sure it is possible since the data is binary (so restricted characters would be invalid). My next thought was to associate a hash string instead of an image within each user object, and then gzip together all of the images, with the hash strings as the names and the XMLencoded tree in the same compmressed file. That seemed really contrived though.

Does anyone know a good approach for this type of issue?

THanks!

Thanks!

+1  A: 

Assuming this isn't just a serializable graph, consider bundling the files together in Jar format. If you already have your data structures working with XMLEncoder, you can reuse this code by saving the data as a jar entry.

If memory serves, the jar library has better support for Unicode name entries than the zip package, which is why I would favour it.

McDowell
This makes sense. Basically serialize your text-format data as XML, and include the XML file + images files all in the jar file.
apenwarr
This makes sense, and I will explore this path. However, I do wonder then what the best practice would be for pulling out the image data for rendering. Is there a way to access the file members of the jar without unpacking it? I do not expect to need to view the images in rapid succession so I do not see any harm in extracting the files each time one is viewed, but if they cannot be placed immediately in memory, then will I have to use temporary files? I then start to get worried about performance (how quickly will it render?) which then opens the whole cacheing can of worms.
Richard
@Richard - look at the `JarFile` class to easily read data from a jar on the file system.
McDowell
A: 

You might consider using an MS JET database (.mdb file) and storing all the stuff in there. That'll also make it easy to examine and edit the data in (for example) MS Access.

apenwarr
A: 

You can employ some virtual file system, which stores it's data in a single container. We develop and offer one of such files sytems, SolFS, however right now there's no Java binding for it. We will release Java JNI interface for SolFS within a month.

Eugene Mayevski 'EldoS Corp