Note:
BAIS: byte array input stream
BAOS: byte array output stream
Yes you can serialize only a part. Here is the twist:
1-You have to write to a BAOS subclass (to avoid arraycopy and get access
to the buffer, for reuse, and the count)
2-you write 1 instance of all common classes you intend to use to the
object stream (this is the learn phase)
3-you flush, and count how many bytes were written.
4-you write your instance and flush
5-you grab only the byte between the mark and the end and save them.
when reading:
1-prepare a static readonly version of the byte[] prefix created earlier,
this is a working cached version of the data you didn't want to save.
remember that it must be exactly the same classes you wrote in phase 2
above.
2-you load your data in another byte[].
3-either you concat the 2 arrays and wrap the OIS over BAIS over byte[],
or better, you use a OIS over sequenceinputstream over 2 BAIS over the 2
byte[].
4-read all the "dummy" prefix objects
5-read your instance.
NOTE:
-the size is definitely smaller, but be warned that the r/w of dummies
are taking much more CPU now.
-String is natively supported like a primitive, but not arrays of it.
-arrays (of any dimensions) of a class are not learned when the class is
learned.
-write your own Externalizable classes and persist yourself, the
readExternal is about 60%-80% of typical readobjects. And it makes
smaller data.
-this trick make data versionning almost impossible.
-you can detect classes by overriding OOS.annotateClass() and loggin to
console for dev purpose.
(e-mail address removed) (Peter) wrote in @posting.google.com: