Re: [Nuiton-utils-devel] [Nuiton-utils-commits] r1936 - in trunk/src: main/java/org/nuiton/util test/java/org/nuiton/util
On Fri, 22 Oct 2010 16:26:09 +0200 chemit <chemit@codelutin.com> wrote:
Le Fri, 22 Oct 2010 15:13:20 +0200 (CEST), bpoussin@users.nuiton.org a écrit :
Ben,
Les méthodes close doivent tjs etre effectuées dans un block finally :)
Oui, cela est vrai pour tout ce qui ouvre des ressources (fichier, bd, ...) Ici ce n'est pas le cas, c'est simplement un tableau en mémoire. Donc le close n'a aucune importance et ne doit pas faire grand chose. Mais, c'est vrai qu'il vaut mieux prendre les bonnes habitudes :)
+ /** + * Use serialization/deserialization to do deep clone of object + * @param e object to clone + * @return new instance of E + * @throws CloneNotSupportedException if some error occur during clone + */ + static public <E> E deepClone(E e) throws CloneNotSupportedException { + try { + ByteArrayOutputStream bos = new ByteArrayOutputStream(); + ObjectOutputStream oos = new ObjectOutputStream(bos); + oos.writeObject(e); + oos.close(); + + ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); + ObjectInputStream ois = new ObjectInputStream(bis); + E result = (E) ois.readObject(); + ois.close(); + + return result; + } catch (Exception eee) { + // on est oblige de faire un log, car CloneNotSupportedException + // ne prend pas d'exception en arguement :( + log.error("Can't clone object", eee); + throw new CloneNotSupportedException(); + } + }
-- Tony Chemit -------------------- tél: +33 (0) 2 40 50 29 28 email: chemit@codelutin.com http://www.codelutin.com _______________________________________________ Nuiton-utils-commits mailing list Nuiton-utils-commits@list.nuiton.org http://list.nuiton.org/cgi-bin/mailman/listinfo/nuiton-utils-commits
-- Benjamin POUSSIN -------------------- tél: +33 (0) 2 40 50 29 28 email: poussin@codelutin.com () campagne du ruban ascii http://www.codelutin.com /\ pour les mails en ascii
participants (1)
-
Benjamin POUSSIN