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 :)
+ /** + * 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