當前位置: 首頁>>代碼示例>>Java>>正文


Java ISerializationSupport類代碼示例

本文整理匯總了Java中com.github.ddth.commons.serialization.ISerializationSupport的典型用法代碼示例。如果您正苦於以下問題:Java ISerializationSupport類的具體用法?Java ISerializationSupport怎麽用?Java ISerializationSupport使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


ISerializationSupport類屬於com.github.ddth.commons.serialization包,在下文中一共展示了ISerializationSupport類的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: toByteArray

import com.github.ddth.commons.serialization.ISerializationSupport; //導入依賴的package包/類
/**
 * Serialize an object to byte array, with a custom class loader.
 * 
 * <p>
 * If the target object implements {@link ISerializationSupport}, this
 * method calls its {@link ISerializationSupport#toBytes()} method;
 * otherwise FST library is used to serialize the object.
 * </p>
 * 
 * @param obj
 * @param classLoader
 * @return
 */
public static byte[] toByteArray(Object obj, ClassLoader classLoader) {
    if (obj instanceof ISerializationSupport) {
        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
        if (classLoader != null) {
            Thread.currentThread().setContextClassLoader(classLoader);
        }
        try {
            return ((ISerializationSupport) obj).toBytes();
        } finally {
            Thread.currentThread().setContextClassLoader(oldClassLoader);
        }
    } else {
        return toByteArrayFst(obj, classLoader);
    }
}
 
開發者ID:DDTH,項目名稱:ddth-commons,代碼行數:29,代碼來源:SerializationUtils.java

示例2: fromByteArray

import com.github.ddth.commons.serialization.ISerializationSupport; //導入依賴的package包/類
/**
 * Deserialize a byte array back to an object, with custom class loader.
 * 
 * <p>
 * If the target class implements {@link ISerializationSupport}, this method
 * calls its {@link ISerializationSupport#toBytes()} method; otherwise FST
 * library is used to serialize the object.
 * </p>
 * 
 * @param data
 * @param clazz
 * @param classLoader
 * @return
 */
public static <T> T fromByteArray(byte[] data, Class<T> clazz, ClassLoader classLoader) {
    if (data == null) {
        return null;
    }
    if (ReflectionUtils.hasInterface(clazz, ISerializationSupport.class)) {
        ClassLoader oldClassLoader = Thread.currentThread().getContextClassLoader();
        if (classLoader != null) {
            Thread.currentThread().setContextClassLoader(classLoader);
        }
        try {
            Constructor<T> constructor = clazz.getDeclaredConstructor();
            constructor.setAccessible(true);
            T obj = constructor.newInstance();
            ((ISerializationSupport) obj).fromBytes(data);
            return obj;
        } catch (InstantiationException | IllegalAccessException | NoSuchMethodException
                | SecurityException | IllegalArgumentException | InvocationTargetException e) {
            throw new DeserializationException(e);
        } finally {
            Thread.currentThread().setContextClassLoader(oldClassLoader);
        }
    }
    return SerializationUtils.fromByteArrayFst(data, clazz, classLoader);
}
 
開發者ID:DDTH,項目名稱:ddth-commons,代碼行數:39,代碼來源:SerializationUtils.java

示例3: fromBytes

import com.github.ddth.commons.serialization.ISerializationSupport; //導入依賴的package包/類
@Override
public ISerializationSupport fromBytes(byte[] data) throws DeserializationException {
    String[] tokens = StringUtils.split(new String(data, UTF8), DELIM);
    version = Integer.parseInt(tokens[0]);
    name = tokens[1];
    return this;
}
 
開發者ID:DDTH,項目名稱:ddth-cache-adapter,代碼行數:8,代碼來源:TestValue.java

示例4: fromBytes

import com.github.ddth.commons.serialization.ISerializationSupport; //導入依賴的package包/類
/**
 * {@inheritDoc}
 * 
 * @since 0.6.0
 */
@Override
public ISerializationSupport fromBytes(byte[] data) throws DeserializationException {
    return fromByteArray(data);
}
 
開發者ID:DDTH,項目名稱:ddth-dao,代碼行數:10,代碼來源:BaseBo.java


注:本文中的com.github.ddth.commons.serialization.ISerializationSupport類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。