All Downloads are FREE. Search and download functionalities are using the official Maven repository.

Alachisoft.NCache.Common.GenericCopier Maven / Gradle / Ivy

There is a newer version: 5.3.3
Show newest version
/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Alachisoft.NCache.Common;

import com.alachisoft.ncache.serialization.core.io.ICompactSerializable;
import com.alachisoft.ncache.serialization.standard.CompactBinaryFormatter;

import java.io.IOException;

/**
 * Will be slow; so testing is required
 *
 * @author Basit Anwer
 */
public class GenericCopier {
    /**
     * Will be slow; so testing is required
     * THere must be a better method to do so. For the moment it is "Gets the job done" code.
     *
     * @param objectToCopy
     * @return
     * @throws IOException
     */
    public static Object DeepCopy(Object objectToCopy) {
        Object obj = null;
        try {
            if (!(objectToCopy instanceof java.io.Serializable) && !(objectToCopy instanceof ICompactSerializable)) {
                //System.err.println("Non serializable Type " + objectToCopy.getClass().toString());
                return objectToCopy;
            }
            obj = CompactBinaryFormatter.fromByteBuffer(CompactBinaryFormatter.toByteBuffer(objectToCopy, ""), "");
        } catch (IOException iOException) {
            //Logger.getLogger(GenericCopier.class.getName()).warning("IOException + " + iOException.getMessage()) ;
            return objectToCopy;
        } catch (ClassNotFoundException classNotFoundException) {
            //Logger.getLogger(GenericCopier.class.getName()).warning("classNotFoundException + " + classNotFoundException.getMessage()) ;
            return objectToCopy;
        }
        return obj;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy