Serialization (beginning & end)
I noticed that every file containing serialized objects begins with a stream header.
From Ivor Horton's JDK 1.3 ed. chapter 9, exercise 5, the code of my Person object file looks like:
ˆ sr SerialNames$Personh¦ù¡ýÃâ· L firstNamet Ljava/lang/String;L surnameq ~ xpt Tomt Bartlettsq ~ t Timt Briggssq ~ t Markt Burdettsq ~ t Robertt Changsq ~ t Pault Coopersq ~ t Andrewt Criddlesq ~ t Williamt Fallonsq ~ t Ivort Hortonsq ~ t Davidt Hudsonsq ~ t Jonathant Jonessq ~ t Laurentt Lafonsq ~ t Jimt MacIntoshsq ~ t Christ Morrissq ~ t Chandimat Nethisinghesq ~ t Ront Phillipssq ~ t Robert FEt Shawsq ~ t Gavint Smythsq ~ t Johnt Timneysq ~ t Andrewt Traceysq ~ t Davidt Whitney
I typed the names in at the prompt, a few persons at a time, running main() more than once. First the existing file was restored in an array. Then each time I input a person, the array expanded to put the person alphabetically in place. Finally the whole array was stored in the file. This exercise gave me a lot of hard work!
MY QUESTION IS:
Suppose I want to add another Person object (Zappa, Frank) to the END of the file, without re-storing the existing ones, is this possible?
I gave it a try, but did not succeed. Perhaps the stream header gets in the way, so that the added objects cannot be read?
ANOTHER QUESTION:
Finding the end of the serialized file was a serious problem. I had to catch an EOFException, while I thought the OptionalDataException was meant for that. Still not very elegant! How come?
Greetings
Francis (I use the SDK1.4 API)
|