commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Stephen Colebourne <scolebou...@btopenworld.com>
Subject Re: [lang] CloneUtils
Date Mon, 06 Jun 2005 12:21:12 GMT
Have a look in SerializationUtils. IIRC this code is
already there.

CloneUtils can wrap the code in SerializationUtils to
achieve its aims, although I'd probably prefer to just
add a method to ObjectUtils rather than creating a new
class for one method.

Stephen


--- Shaun Kalley <shaun_kalley@telus.net> wrote:

> I've included my code below.  I have another if
> you're able to answer 
> it: why is the lang subproject home to classes
> dealing with 
> serialization?  Shouldn't they be part of the IO
> subproject?
> 
> Thanks,
> Shaun
> 
>     /**
>      * <p>Clones a serializable object by
> serializing and deserializing 
> it.</p>
>      *
>      * @param obj the object to clone.
>      * @return a clone of the object, or null if the
> object is null.
>      * @throws SerializationException if the
> serialization process fails.
>      */
>     public static Object
> cloneSerializable(Serializable obj) throws 
> SerializationException {
>         if (obj == null) {
>             return null;
>         }
>         ObjectOutputStream oos = null;
>         ObjectInputStream ois = null;
>         try {
>             ByteArrayOutputStream baos = new
> ByteArrayOutputStream(512);
>             oos = new ObjectOutputStream(baos);
>             oos.writeObject(obj);
>             oos.flush();
>             ois = new ObjectInputStream(new 
> ByteArrayInputStream(baos.toByteArray()));
>             return ois.readObject();
>         } catch (Exception e) {
>             throw new SerializationException("Failed
> to clone 
> serializable object.", e);
>         } finally {
>             if (ois != null) {
>                 try {
>                    ois.close();
>                 } catch (IOException ignored) {
>                 }
>             }
>             if (oos != null) {
>                 try {
>                     oos.close();
>                 } catch (IOException ignored) {
>                 }
>             }
>         }
>     }
>    
> 
> 
> Kevin Gessner wrote:
> 
> >Thanks Shaun - I'd be happy to have the code if
> you'll send it along.
> >
> >Kevin
> >
> >On 6/4/05, Shaun Kalley <shaun_kalley@telus.net>
> wrote:
> >  
> >
> >>The only substantial difference in my code is a
> shortcut to return null
> >>if the object is null.  (Sorry to send two
> replies!)
> >>
> >>Shaun
> >>
> >>
> >>James Carman wrote:
> >>
> >>    
> >>
> >>>SerializationUtils already has a clone() method. 
> Is your code different
> >>>      
> >>>
> >>>from that?
> >>    
> >>
> >>>-----Original Message-----
> >>>From: Shaun Kalley
> [mailto:shaun_kalley@telus.net]
> >>>Sent: Saturday, June 04, 2005 4:31 PM
> >>>To: Jakarta Commons Developers List
> >>>Subject: Re: [lang] CloneUtils
> >>>
> >>>Hi, Kevin and everyone,
> >>>
> >>>I've got code for cloning serializable objects
> that I'd be happy to
> >>>contribute to the project.  Let me know if you'd
> like it as a starting
> >>>point.
> >>>
> >>>Thanks,
> >>>Shaun Kalley
> >>>
> >>>
> >>>Kevin Gessner wrote:
> >>>
> >>>
> >>>
> >>>      
> >>>
> >>>>Hello all,
> >>>>
> >>>>In the interest of jumping feet first into
> commons-lang, I'm hoping to
> >>>>start work on CloneUtils (from the tasks list). 
> Before I start any
> >>>>serious design/coding, I'd like to ask for any
> suggestions as to
> >>>>features of the class (assuming, of course, that
> no one has anything
> >>>>completed already).  I was planning on
> implementing serialization
> >>>>cloning, and maybe super-simple public fields
> cloning if it's worth
> >>>>it.  I would appreciate any
> suggestions/tips/etc. anyone has to offer.
> >>>>
> >>>>Thanks,
> >>>>Kevin Gessner
> >>>>
>
>>>>---------------------------------------------------------------------
> >>>>To unsubscribe, e-mail:
> commons-dev-unsubscribe@jakarta.apache.org
> >>>>For additional commands, e-mail:
> commons-dev-help@jakarta.apache.org
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>
> >>>>        
> >>>>
> >>>
>
>>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail:
> commons-dev-unsubscribe@jakarta.apache.org
> >>>For additional commands, e-mail:
> commons-dev-help@jakarta.apache.org
> >>>
> >>>
>
>>>---------------------------------------------------------------------
> >>>To unsubscribe, e-mail:
> commons-dev-unsubscribe@jakarta.apache.org
> >>>For additional commands, e-mail:
> commons-dev-help@jakarta.apache.org
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>      
> >>>
> >>
> >>    
> >>
> >
>
>---------------------------------------------------------------------
> >To unsubscribe, e-mail:
> commons-dev-unsubscribe@jakarta.apache.org
> >For additional commands, e-mail:
> commons-dev-help@jakarta.apache.org
> >
> >
> >
> >  
> >
> 
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message