I want to be able to "peek" at my ObjectInputStream. I thought mark / reset would of worked, but that is not supported with ObjectInputStream. I need to use ObjectInputStream because I am reading and writing serialized objects. Any thoughts on how to accomplish this?
Andrew Mcmurray wrote:when I call the mark supported method it returns false. I need to use ObjectInputStream because I am writing and reading in serialized objects.
Indeed, the Javadoc allows you to conclude that it will, so I'm not sure why Ninad thinks otherwise.
Anyway: do you want to peek in the sense of reading an object, then reading it again? Or just check if there are some bytes to read, or what, exactly? If I know what you want to do, I'm sure I can help you figure out a solution.
So basically what I am doing is a merge sort. I have separate file chunks and I need to "peek" at the first record(object) of each file and then return the smallest one. I only want to advance the file pointer in file where the smallest record was found. Does this help?
author and iconoclast
If they're files, do you have the paths? The very easiest thing to do would be to just open the files, read an object from each, then close those streams and open new ones.
A more complicated alternative that would work with network streams as well as files would be to create a wrapper class for an ObjectInputStream called, say, "ObjectSource". It would have a method getNextObject which looked something like (just off the top of my head, not tested)
Then you call getNextObject() to get an object from the stream, or unreadObject() to return an object to be read again in FIFO order.
Joined: Sep 24, 2005
I will give your second idea a shot. For the 1st idea I do have the paths to the files, but I am dealing with 100K records per file and on average ten files(chunks) so I think the overhead of opening and closing the stream might be a performance killer.