@SuppressWarnings("unchecked") public static <T> T copy(T orig, ObjectInputStreamFactory factory) { T obj = null; ObjectOutputStream out = null; ObjectInputStream in = null; try { // Write the object out to a byte array ByteArrayIOStream byteStream = new ByteArrayIOStream(); out = new ObjectOutputStream(byteStream); out.writeObject(orig); out.close(); // Make an input stream from the byte array and read // a copy of the object back in. in = factory.create(byteStream.getInputStream(), null); obj = (T)in.readObject(); } catch(IOException e) { log.error("IO exception", e); } catch(ClassNotFoundException cnfe) { log.error("class not found exception", cnfe); } finally { closeQuietly(in); closeQuietly(out); } return obj; }
public static <T> T copy(T orig) { return copy(orig, (is, codebase) -> new ObjectInputStream(is)); }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { final Object[] argsCopy; if (args == null) { argsCopy = null; } else { argsCopy = new Object[args.length]; for (int i = 0 ; i < args.length ; i++) { argsCopy[i] = SerializingUtils.copy(args[i], factory); if (argsCopy[i] == null && args[i] != null) { throw new NotSerializableException("failed to serialize object" + " in method " + method + " with arg number " + i + " with class " + args[i].getClass() + " with value " + args[i]); } } } try { return SerializingUtils.copy(method.invoke(delegate, argsCopy), factory); } catch (InvocationTargetException e) { throw SerializingUtils.copy(e.getCause()); } }
@SuppressWarnings("unchecked") public static <T> T copy(T orig, ObjectInputStreamFactory factory) { T obj = null; ObjectOutputStream out = null; ObjectInputStream in = null; try { // Write the object out to a byte array ByteArrayIOStream byteStream = new ByteArrayIOStream(); out = new ObjectOutputStream(byteStream); out.writeObject(orig); out.close(); // Make an input stream from the byte array and read // a copy of the object back in. in = factory.create(byteStream.getInputStream(), null); obj = (T)in.readObject(); } catch(IOException e) { log.error("IO exception", e); } catch(ClassNotFoundException cnfe) { log.error("class not found exception", cnfe); } finally { closeQuietly(in); closeQuietly(out); } return obj; }
public static <T> T copy(T orig) { return copy(orig, (is, codebase) -> new ObjectInputStream(is)); }
@Override public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { final Object[] argsCopy; if (args == null) { argsCopy = null; } else { argsCopy = new Object[args.length]; for (int i = 0 ; i < args.length ; i++) { argsCopy[i] = SerializingUtils.copy(args[i], factory); if (argsCopy[i] == null && args[i] != null) { throw new NotSerializableException("failed to serialize object" + " in method " + method + " with arg number " + i + " with class " + args[i].getClass() + " with value " + args[i]); } } } try { return SerializingUtils.copy(method.invoke(delegate, argsCopy), factory); } catch (InvocationTargetException e) { throw SerializingUtils.copy(e.getCause()); } }