serialize only a litte part?

Discussion in 'Java' started by Peter, Jan 10, 2004.

  1. Peter

    Peter Guest

    Hi
    For example, I have serialize a hugh object into file system. A
    little part of the object change. How can i only serialize that little
    part? or i have to serialize the whole object again?

    thanks
    from Peter ()
     
    Peter, Jan 10, 2004
    #1
    1. Advertising

  2. Peter

    Tony Morris Guest

    You must serialize the entire object again.
    The only other possible alternative is if you know the offset into the file
    of the changed data and use a java.io.RandomAccessFile to change it, which,
    in my opinion, is not worth it, since it is prone to error and
    maintainability issues.

    --
    Tony Morris
    (BInfTech, Cert 3 I.T., SCJP[1.4], SCJD)
    Software Engineer
    IBM Australia - Tivoli Security Software

    "Peter" <> wrote in message
    news:...
    > Hi
    > For example, I have serialize a hugh object into file system. A
    > little part of the object change. How can i only serialize that little
    > part? or i have to serialize the whole object again?
    >
    > thanks
    > from Peter ()
     
    Tony Morris, Jan 10, 2004
    #2
    1. Advertising

  3. Peter

    NOBODY Guest

    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.



    (Peter) wrote in news:a52de42d.0401091946.55ad0f57
    @posting.google.com:

    > Hi
    > For example, I have serialize a hugh object into file system. A
    > little part of the object change. How can i only serialize that little
    > part? or i have to serialize the whole object again?
    >
    > thanks
    > from Peter ()
     
    NOBODY, Jan 15, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Gordz
    Replies:
    3
    Views:
    3,960
    John Oakes
    Jun 7, 2004
  2. Toralf
    Replies:
    2
    Views:
    2,534
    Ken Dopierala Jr.
    Oct 4, 2004
  3. Bob
    Replies:
    3
    Views:
    1,824
    Steve C. Orr [MVP, MCSD]
    Nov 11, 2004
  4. Jack
    Replies:
    8
    Views:
    296
  5. Csaba Henk

    "Litte Ruby" book

    Csaba Henk, Jun 15, 2004, in forum: Ruby
    Replies:
    13
    Views:
    235
    Brian Marick
    Jul 1, 2004
Loading...

Share This Page