Popular Posts
javax.net.ssl.SSLHandshakeException: Connection closed by peer in Android 5.0 Lollipop Recently, there is a error occurs when access website via ssl connection like below although it worked fine several days ago. // Enable SSL... Close window without confirm (I.E only) window.opener=null; window.open('','_self'); window.close(); focus on validating function focusOnInvalidControl() {     for (var i = 0; i < Page_Validators.length; i++) {         if (!Page_Validators[i].isvalid) {     ...
Blog Archive
Stats
Clone any object
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;

import bruce.lib.swing.JTextBox;

public class CloneObject {

    public static Object clone(Object source) {
        Object newObject = new Object();
        ObjectOutputStream ooStr = null;
        try {
            ByteArrayOutputStream baoStr = new ByteArrayOutputStream();
            ooStr = new ObjectOutputStream(baoStr);
            ooStr.writeObject(source);
            ooStr.flush();
            ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(baoStr.toByteArray()));
            newObject = in.readObject();
        } catch (ClassNotFoundException ex) {
            Logger.getLogger(CloneObject.class.getName()).log(Level.SEVERE, null, ex);
        } catch (IOException ex) {
            Logger.getLogger(CloneObject.class.getName()).log(Level.SEVERE, null, ex);
        } finally {
            try {
                ooStr.close();
            } catch (IOException ex) {
                Logger.getLogger(CloneObject.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
        return newObject;

    }

    /**
     * @param args
     */
    public static void main(String[] args) {
        // TODO Auto-generated method stub

        JTextBox textbox = new JTextBox("A simple textbox", 20);
        System.out.printf("Hashcode : %d%n", textbox.hashCode());

        JTextBox clonedTextBox = (JTextBox) clone(textbox);
        System.out.printf("Cloned hashcode : %d%n", clonedTextBox.hashCode());
        System.out.printf("Cloned text : %s%n", clonedTextBox.getText());

    }

}