Delta
Delta

Reputation: 547

Iterate through all serialized objects

what is available way in serialization API to loop through all objects stored in media(file/db) other than catching EOFException in while(true) loop, adding number of objects count at the start of file before writing objects or storing array or collection in file instead of individual objects? If different type of objects are stored in file and they are not stored through array/collection, how to iterate using ObjectInputStream?

Upvotes: 1

Views: 1972

Answers (1)

Eugene Retunsky
Eugene Retunsky

Reputation: 13139

All ways work:

  1. Store the length of the file in the beginning
  2. Saving collections (basically it does (1) inside)
  3. Writing some EndOfFile object at the end.
  4. Catching EOFException

No other options are available (as far as I'm aware).

Upvotes: 3

Related Questions