aspose file tools
The moose likes Java in General and the fly likes Object Serialization Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Object Serialization" Watch "Object Serialization" New topic
Author

Object Serialization

Ole Kristian
Greenhorn

Joined: Jul 02, 2001
Posts: 7
Hi!
I need some help here. I have a file which contains serialized objects. What I want to do is to seek backwards in this file. That is : Seek backwards from anywhere in the file and read the objects. It's easy enough to read and write objects when I go from the beginning to the end of the file, but what about the other way?
Appreciate some help here:-)


Ole Kristian
Cindy Glass
"The Hood"
Sheriff

Joined: Sep 29, 2000
Posts: 8521
Do you have (or could you put) a delimiter in the file that you could tokenize on?


"JavaRanch, where the deer and the Certified play" - David O'Meara
pascal betz
Ranch Hand

Joined: Jun 19, 2001
Posts: 547
hi,
perhaps you can put the size of the serialiezed object in the file too ?

pascal
Chris Camisa
Greenhorn

Joined: Jun 20, 2001
Posts: 4
If you look in "Java 2 - Unleashed" by Jamie Jaworski
...
...
In the Input/Output Streams section it reads.
{
The Random AccessFile Class
The RandomAccessFile class provides the capability to perform I/O directly to specific locations within a file. The name random access comes from the fact that data can be read from or written to random locations within a file rather than as a continus stream of information. Random access is supported through the seek() method, which allows the pointer corresponding to the current file position to be set to arbitrary locations within the file.
RandomAccessFile implements both the DataInput and DataOutput interfaces. This provides the cability to perform I/O using primitive types.
RandomAccessFile also supports basic file read/write permissions, allowing files to be accessed in read-only or read-write modes. A mode stream argument is passed to the RandomAccessFile constructor as r or rw, indicating read-only and read-write file access. The read-only access attribute may be used to prevent a file from being inadvertently modified.
RandomAccessFile introduces several new methods besides those inherited from Object and implemented from DataInput and DataOutput. These methods include seek(), getFilePointer(), and length(). The seek() method sets the file pointer to a particular location within the file. The getFilePointer() method returns the current location of the file pointer. The length() method returns the length of the file in bytes.
}

Wouldn't that allow you to rebuild the file with primitive types?
If you rebuild it, put them in the order you need so that they can be read from the beginning to the end.
Do you think that would work? Could you just put the parts of the file together yourself in the order you need?
...since you can't read it backwards anyway...?
--==]Chris Camisa[==--
Ole Kristian
Greenhorn

Joined: Jul 02, 2001
Posts: 7
Well, I had hoped that I could use some sort of readObject() method on this problem..
The readObject()/writeObject() methods don't work with RandomAccessFile do they?
It's just primitive types that can be written and read to/from a file then?
I have also thought about loading the whole file in the computers memory (use an array of some sort), but I don't like the idea because these files I talking about can have a size uptil 10 MB.
Isn't that bad memory managent to use so much memory?
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Object Serialization
 
Similar Threads
greedy quantifier concept doubt
RandomAccessFile & ObjectInputStream
I/O
seek() vs skipBytes()
JTable challenge