0

I am reading across different methods/tools to serialize objects and I'm looking for an up-to-date suggestion for my application (as I can find a lot of similar question+answers from 2012, 2010, ...).

I need to write some java objects to disk. I would love to save disk space as these objects may contain a lot of data and I would love to do it rather fast.

So far it has been done with java standard serialization but the implementation is probably not very good (no explicit serialID set, ...). I read about the kryo library but I'm a bit afraid of using 3rd party libraries as I don't know how well they are maintained/ how common is their usage. Or shall I just improve the use of the serializable interface and if yes, is there any good documentation on proper implementation?

Antje Janosch
  • 1,154
  • 5
  • 19
  • 37

1 Answers1

1

This solution helps to save space on disk and is based on Java standard library

ObjectOutputStream oos = new ObjectOutputStream(new GZIPOutputStream(new FileOutputStream("file")));
oos.writeObject(obj);
...

ObjectInputStream ois = new ObjectInputStream(new GZIPInputStream(new FileInputStream("file")));
obj = ois.readObject();
...
Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275