• 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

Reading\writing serialized objects via Readable

 
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Im working on a task where I need to save and load object information to file.
The format in the file does not matter, so it doesnt matter exactly how I save\load it. However, I am required to use the method 'read ( Readable arg0, Readable arg1 )' to write the file, and 'write ( PrintStream arg0, PrintStream arg1 )' to save it.

I wish to use serializing to save the objects to file, as it is a very quick and easy way to save objects with all their information and relations.
The problem is that the only I way I know to save with serializing, is by using ObjectInputStream. As mentioned, I need to implement it in a method that requires Readable.
I've googled for some hours on how to deal with this, and I haven't found the answer to my two questions:
- Is it possible to save\load serialized objects with a reader instead of a stream?
- Is it possible to turn a reader into a stream? I know that I can do the opposite, but that doesn't solve my problem.

Thanks for any help
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Kari Nordmann wrote:- Is it possible to save\load serialized objects with a reader instead of a stream?



I don't think so. Readers are used for processing encoded text data. Running binary data through them results in information being lost.

Kari Nordmann wrote:
- Is it possible to turn a reader into a stream? I know that I can do the opposite, but that doesn't solve my problem.



For the reason cited above, I don't think so.
If you are REALLY desperate, you could try text-encoding the binary data and using a Reader to send the resulting String. That's how we move binary data across SNMP, which is a text-based protocol. I can't imagine it would perform well, but if it's your only option. . .
reply
    Bookmark Topic Watch Topic
  • New Topic