Serializing PriorityQueue<type> not working?

T

Twisted

I have a spot where a PriorityQueue<foo> is serialized to a file. A
FileOutputStream is opened successfully, an ObjectOutputStream created
on it, and the queue is fed to writeObject(). The stream is closed. No
exceptions occur but the 1.3KB file generated is nowhere near big
enough, and won't deserialize later. Inspecting the queue just before
serialization reveals it to be full of the expected items. The type foo
is serializable and really just a glorified struct of mostly primitive
types, plus a String and a URL. I've checked that java.net.URL and
java.util.PriorityQueue are serializable.

Adding a flush() of the object output stream just before closing it
doesn't make any difference.

What's going on?
 
T

Twisted

Bah, my bad. I forgot to put "implements Serializable" on the
struct-thingie. It should have produced an exception when the queue was
fed to the object output stream, but for some reason it didn't, or the
IDE didn't tell me about it, or something like that.

It now generates a file about 50 times larger, and hex editing it shows
lots of URL strings inside the file, which is what I expected. Now to
see if it actually deserializes OK. :)
 
Joined
Oct 14, 2012
Messages
1
Reaction score
0
Hey could you please share Serializable PriorityQueue code somewhere and post a link . I need to use the same.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top