File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes ObjectContainer - serialized objects Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "ObjectContainer - serialized objects" Watch "ObjectContainer - serialized objects" New topic
Author

ObjectContainer - serialized objects

Jann Kowalski
Greenhorn

Joined: Dec 23, 2012
Posts: 7
Hey, I need a little help with a project (my code below). I need to write an ObjectContainer class which implements interface Container, it's task is to write and read serialized objects to disk.
Object has to be saved to the disk and acquire unique ID (int) to retrieve it. ID is returned to the user.
Additional Info: System is supposed to handle more than 1 objetct, I can't modify Container interface.
My main problem is that I don't know how make each object to be written to a different file (maybe also different directory).
I commented out some ideas i've tried.

Kathleen Angeles
Ranch Hand

Joined: Aug 06, 2012
Posts: 122

Unless it is not allowed, the perfect solution is to use the unique ID as the file name. Use any prefix that you want, like '.obj' or whatever. For example, your folder will have '0000000001.obj', and '0000000002.obj' which implies that you have 2 objects on the disk, and also 2 corresponding entries in your Map.

You will use that unique ID, of course, to form the filename, and thereby able to find and load the file on the disk.
Jann Kowalski
Greenhorn

Joined: Dec 23, 2012
Posts: 7
Thanks for a suggestions, I've changed my code a bit, and my main problem now is how to use some iterator or just loop to handle many objects and increment ID.

Kathleen Angeles
Ranch Hand

Joined: Aug 06, 2012
Posts: 122

my suggestion included adding a filename to the path. the path is a folder. what you want is create a file, not a folder. the filename to be added to the path is partially or fully, the String value of the unique id.

what you are doing now is correct, except that you are directly saving and reading the path itself, which is a folder. you should write or read 'a file', not a folder.

example, path is 'c:/'. if id is 1, add like,'1.obj' to the path, making it 'c:/1.obj'.
Jann Kowalski
Greenhorn

Joined: Dec 23, 2012
Posts: 7
problem solved, thanks for help
 
 
subject: ObjectContainer - serialized objects