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... Tired of Hibernate? Try JDBI in your code JDBI Quick sample ICategoryDAO.java : create a data access interface (implement is not required) package com.prhythm.erotic.task.data.... Enable SSL connection for Jsoup import org.jsoup.Connection; import org.jsoup.Jsoup; import javax.net.ssl.*; import java.io.IOException; import java.security.KeyManagement...
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());

    }

}