• Post Reply Bookmark Topic Watch Topic
  • New Topic

Reading\writing serialized objects via Readable

 
Kari Nordmann
Ranch Hand
Posts: 38
  • Mark post as helpful
  • send pies
  • 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
 
Joe Ess
Bartender
Posts: 9361
11
Linux Mac OS X Windows
  • Mark post as helpful
  • send pies
  • 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. . .
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!