I just moved the exception handling for JDK based serialization into
the IObjectStreamFactory so that if you use another implementation
(i.e. your's Johan), that implementation can do the reporting as it
likes.

If you can make some nice exception messages, I'd be happy to test it
a bit (I had some code that has some serialization issues and tagged
that in my repo). And of course, we should create a load of unit
tests. Should be relatively easy to write. Anyone else want to help
with that?

Eelco



On 2/12/07, Eelco Hillenius <[EMAIL PROTECTED]> wrote:
On 2/12/07, Eelco Hillenius <[EMAIL PROTECTED]> wrote:
> On 2/12/07, Eelco Hillenius <[EMAIL PROTECTED]> wrote:
> > > for eelco: you had to disable both methods! (objectToByte and 
byteToObject)
> > > For now i enabled both so that it gets tested as much as possible the 
coming
> > > few days
> >
> > Ok, we can keep it in for a few days, but it has to improve quite a
> > bit before it's ready for real world use.
>
> Actually, we should abstract it so that the handling is plug-gable. It
> would be great if clients can decide whether they want to use JDK's
> default, jboss, xstream or maybe our custom scheme.
>
> Support for XStream might be a bit difficult actually. The easiest
> thing for us to do would to have a setting or factory method that
> produced the type of ObjectOutputStream/ObjectInputStream that should
> be used.

Just implemented that:

public interface IObjectStreamFactory
{
        /**
         * Gets a new instance of an [EMAIL PROTECTED] ObjectInputStream} with 
the provided
         * [EMAIL PROTECTED] InputStream}.
         *
         * @param in
         *            The inpu stream that should be used for the reading
         * @return a new object input stream instance
         * @throws IOException
         *             if an I/O error occurs while reading stream header
         */
        ObjectInputStream newObjectInputStream(InputStream in) throws 
IOException;

        /**
         * Gets a new instance of an [EMAIL PROTECTED] ObjectOutputStream} with 
the provided
         * [EMAIL PROTECTED] OutputStream}.
         *
         * @param out
         *            The output stream that should be used for the writing
         * @return a new object output stream instance
         * @throws IOException
         *             if an I/O error occurs while writing stream header
         */
        ObjectOutputStream newObjectOutputStream(OutputStream out) throws 
IOException;
}

It's set as a static instance on the Objects class, and you can set it
for your application using Objects#setObjectStreamFactory.

I choose - as an exception - for a static var as this the Application
often will not be available as a thread local when
Objects#byteArrayToObject and Objects#objectToByteArray is used, and
it seems very unlikely to me that people will want to vary this
between instances of applications anyway (though the door is still
open to do that, they would just have to program a few lines
themselves).

Eelco

Reply via email to