@@ -0,0 +1,3708 @@
+package com.bluecatcode.common.io;%0A%0Aimport java.io.*;%0A%0A/**%0A * Utility for making deep copies (vs. clone()'s shallow copies) of%0A * objects. Objects are first serialized and then deserialized. Error%0A * checking is fairly minimal in this implementation. If an object is%0A * encountered that cannot be serialized (or that references an object%0A * that cannot be serialized) an exception is thrown.%0A */%0Apublic class SimpleDeepCopy %7B%0A%0A    /**%0A     * Returns a copy of the object.%0A     */%0A    public static %3CT extends Serializable%3E T copy(T original) %7B%0A        //noinspection unchecked%0A        return (T) deserialize(serialize(original));%0A    %7D%0A%0A    /**%0A     * %0A     * @param object the object to serialize%0A     * @param outputStream the output stream to use%0A     * @return the output stream with serialized representation of the object%0A     * @throws IllegalArgumentException if OutputStream is null%0A     * @throws IllegalStateException is an error occurs during serialization%0A     */%0A    public static OutputStream serialize(Serializable object, OutputStream outputStream) %7B%0A        if (outputStream == null) %7B%0A            throw new IllegalArgumentException(%22Expected non-null OutputStream%22);%0A        %7D%0A%0A        ObjectOutputStream out = null;%0A        try %7B%0A            out = new ObjectOutputStream(outputStream);%0A            out.writeObject(object);%0A            out.flush();%0A        %7D catch (IOException e) %7B%0A            throw new IllegalStateException(e);%0A        %7D finally %7B%0A            try %7B%0A                if (out != null) %7B%0A                    out.close();%0A                %7D%0A            %7D catch (IOException e) %7B%0A                // Empty%0A            %7D%0A        %7D%0A        return outputStream;%0A    %7D%0A%0A    /**%0A     * @param object the object to serialize%0A     * @return the byte%5B%5D with serialized representation of the object%0A     * @throws IllegalArgumentException if OutputStream is null%0A     * @throws IllegalStateException is an error occurs during serialization%0A     */%0A    public static byte%5B%5D serialize(Serializable object) %7B%0A        ByteArrayOutputStream byteOut = new ByteArrayOutputStream(512);%0A        serialize(object, byteOut);%0A        return byteOut.toByteArray();%0A    %7D%0A%0A    /**%0A     * @param inputStream the input stream to deserialize%0A     * @return the deserialized object%0A     * @throws IllegalArgumentException if input stream is null%0A     * @throws IllegalStateException is an error occurs during deserialization%0A     */%0A    public static Object deserialize(InputStream inputStream) %7B%0A        if (inputStream == null) %7B%0A            throw new IllegalArgumentException(%22Expected non-null InputStream%22);%0A        %7D%0A        %0A        ObjectInputStream input = null;%0A        Object object;%0A        try %7B%0A            input = new ObjectInputStream(inputStream);%0A            object = input.readObject();%0A        %7D catch (ClassNotFoundException %7C IOException e) %7B%0A            throw new IllegalStateException(e);%0A        %7D finally %7B%0A            try %7B%0A                if (input != null) %7B%0A                    input.close();%0A                %7D%0A            %7D catch (IOException e) %7B%0A                // Empty%0A            %7D%0A        %7D%0A        return object;%0A    %7D%0A%0A    /**%0A     * @param objectData the byte array to deserialize%0A     * @return the deserialized object%0A     * @throws IllegalArgumentException if byte%5B%5D is null%0A     * @throws IllegalStateException is an error occurs during deserialization%0A     */%0A    public static Object deserialize(byte%5B%5D objectData) %7B%0A        if (objectData == null) %7B%0A            throw new IllegalArgumentException(%22Expected non-null byte%5B%5D%22);%0A        %7D%0A        ByteArrayInputStream byteIn = new ByteArrayInputStream(objectData);%0A        return deserialize(byteIn);%0A    %7D%0A%0A%7D%0A

Create SimpleDeepCopy.java