Alachisoft.NCache.Common.GenericCopier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of nc-common Show documentation
Show all versions of nc-common Show documentation
Internal package of Alachisoft.
/*
* 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;
}
}