best practices question: How to save a collection of images and a java object in a single file? File

Posted by Richard on Stack Overflow See other posts from Stack Overflow or by Richard
Published on 2010-06-06T21:01:57Z Indexed on 2010/06/06 21:12 UTC
Read the original article Hit count: 190

Filed under:
|
|
|
|

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!

© Stack Overflow or respective owner

Related posts about java

Related posts about image