views:

56

answers:

1

Good day. I know that in order to save object state in Java I should use serialization. But in every single topic about serialization states that I must save my object somewhere (disk, network). My problem is that I'm not allowed to do so. I need a way to save and recover object state without writing it on "external" memory. Maybe to save it on heap or stack... Please don't offer to clone it, I'm not allowed to do so as well. Thanks.

+5  A: 

You can serialize to a ByteArrayOuputStream. Just pass one to the ObjectOutputStream constructor. When you're done, you can call toByteArray

Matthew Flaschen
That's can be a solution. Thanks!
TryHarder