• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

ObjectInputStream peek

 
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all

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?

Thanks,

AMD
 
Ranch Hand
Posts: 814
Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Would you explain why do you want to use ObjectInputStream ?

I thought mark / reset would of worked, but that is not supported with ObjectInputStream.


2. mark & reset are supported in ObjectInputStream see Java documentation for details.
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when I call the mark supported method it returns false. I need to use ObjectInputStream because I am writing and reading in serialized objects.
 
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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.
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ernest,

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?

Thanks,

AMD
 
Ernest Friedman-Hill
author and iconoclast
Posts: 24207
46
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Andrew Mcmurray
Ranch Hand
Posts: 188
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Ernest

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.

Thanks,

AMD
 
Ninad Kulkarni
Ranch Hand
Posts: 814
Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Andrew Mcmurray wrote:when I call the mark supported method it returns false.

Andrew I agree with you

Ernest Friedman-Hill wrote:Indeed, the Javadoc allows you to conclude that it will, so I'm not sure why Ninad thinks otherwise.

Thanks Ernest for nice explaination. Ignore my previous post It was wrong.
 
reply
    Bookmark Topic Watch Topic
  • New Topic