本文整理汇总了Java中com.dyuproject.protostuff.Schema类的典型用法代码示例。如果您正苦于以下问题:Java Schema类的具体用法?Java Schema怎么用?Java Schema使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Schema类属于com.dyuproject.protostuff包,在下文中一共展示了Schema类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: serialize
import com.dyuproject.protostuff.Schema; //导入依赖的package包/类
/**
* 序列化对象
*
* @param obj
* @return
*/
public static <T> byte[] serialize(T obj) {
if (obj == null) {
throw new RuntimeException("序列化对象(" + obj + ")!");
}
@SuppressWarnings("unchecked")
Schema<T> schema = (Schema<T>) RuntimeSchema.getSchema(obj.getClass());
LinkedBuffer buffer = LinkedBuffer.allocate(1024 * 1024);
byte[] protostuff = null;
try {
protostuff = ProtostuffIOUtil.toByteArray(obj, schema, buffer);
} catch (Exception e) {
throw new RuntimeException("序列化(" + obj.getClass() + ")对象(" + obj + ")发生异常!", e);
} finally {
buffer.clear();
}
return protostuff;
}
示例2: serialize
import com.dyuproject.protostuff.Schema; //导入依赖的package包/类
@Override
public void serialize(OutputStream output, Object object) {
Class cls = object.getClass();
LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);
try {
Schema schema = getSchema(cls);
ProtostuffIOUtil.writeTo(output, object, schema, buffer);
} catch (Exception e) {
throw new IllegalStateException(e.getMessage(), e);
} finally {
buffer.clear();
}
}
示例3: get
import com.dyuproject.protostuff.Schema; //导入依赖的package包/类
private Schema<?> get(final Class<?> cls, Cache<Class<?>, Schema<?>> cache) {
try {
return cache.get(cls, () -> RuntimeSchema.createFrom(cls));
} catch (ExecutionException e) {
return null;
}
}
示例4: deserialize
import com.dyuproject.protostuff.Schema; //导入依赖的package包/类
@Override
public <T> T deserialize(byte[] bytes, Class<T> clz) throws IOException, ClassNotFoundException {
try {
T message = (T) objenesis.newInstance(clz);
Schema<T> schema = getSchema(clz);
ProtostuffIOUtil.mergeFrom(bytes, message, schema);
return message;
} catch (Exception e) {
throw new IllegalStateException(e.getMessage(), e);
}
}
示例5: serialize
import com.dyuproject.protostuff.Schema; //导入依赖的package包/类
@Override
public byte[] serialize(Object msg) throws IOException {
LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);
try {
Schema schema = getSchema(msg.getClass());
byte[] arr = ProtostuffIOUtil.toByteArray(msg, schema, buffer);
return arr;
} finally {
buffer.clear();
}
}
示例6: getSchema
import com.dyuproject.protostuff.Schema; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private static <T> Schema<T> getSchema(Class<T> cls) {
Schema<T> schema = (Schema<T>) cachedSchema.get(cls);
if (schema == null) {
schema = RuntimeSchema.createFrom(cls);
cachedSchema.put(cls, schema);
}
return schema;
}
示例7: deSerialize
import com.dyuproject.protostuff.Schema; //导入依赖的package包/类
/**
* 反序列化对象
*
* @param param 需要反序列化的byte []
* @param clazz
* @return 对象
* @throws TransactionException
*/
@Override
public <T> T deSerialize(byte[] param, Class<T> clazz) throws TransactionException {
T object;
try( ByteArrayInputStream inputStream = new ByteArrayInputStream(param)) {
Class cls = clazz;
object = OBJENESIS_STD.newInstance((Class<T>) cls);
Schema schema = getSchema(cls);
ProtostuffIOUtil.mergeFrom(inputStream, object, schema);
return object;
} catch (Exception e) {
throw new TransactionException(e.getMessage(), e);
}
}
示例8: get
import com.dyuproject.protostuff.Schema; //导入依赖的package包/类
private Schema<?> get(final Class<?> cls, Cache<Class<?>, Schema<?>> cache) {
try {
return cache.get(cls, new Callable() {
@Override
public Object call() throws Exception {
return RuntimeSchema.createFrom(cls);
}
});
} catch (ExecutionException e) {
return null;
}
}
示例9: serialize
import com.dyuproject.protostuff.Schema; //导入依赖的package包/类
@Override
public byte[] serialize(Object obj) throws SerializerException {
Class cls = obj.getClass();
LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);
ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
try {
Schema schema = getSchema(cls);
ProtostuffIOUtil.writeTo(outputStream, obj, schema, buffer);
} catch (Exception e) {
throw new SerializerException(e.getMessage(), e);
} finally {
buffer.clear();
}
return outputStream.toByteArray();
}
示例10: deSerialize
import com.dyuproject.protostuff.Schema; //导入依赖的package包/类
@Override
public <T> T deSerialize(byte[] param, Class<T> clazz) throws SerializerException {
T object;
try {
ByteArrayInputStream inputStream = new ByteArrayInputStream(param);
Class cls = clazz;
object = objenesis.newInstance((Class<T>) cls);
Schema schema = getSchema(cls);
ProtostuffIOUtil.mergeFrom(inputStream, object, schema);
return object;
} catch (Exception e) {
throw new SerializerException(e.getMessage(), e);
}
}
示例11: serialize
import com.dyuproject.protostuff.Schema; //导入依赖的package包/类
public <T> byte[] serialize(T obj) {
Class<T> cls = (Class<T>) obj.getClass();
LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);
try {
Schema<T> schema = getSchema(cls);
return ProtostuffIOUtil.toByteArray(obj, schema, buffer);
} catch (Exception e) {
throw new RuntimeException(e);
} finally {
buffer.clear();
}
}
示例12: deSerialize
import com.dyuproject.protostuff.Schema; //导入依赖的package包/类
/**
* 反序列化对象
*
* @param param 需要反序列化的byte []
* @param clazz clazz
* @return 对象
* @throws MythException 异常
*/
@Override
public <T> T deSerialize(byte[] param, Class<T> clazz) throws MythException {
T object;
try {
ByteArrayInputStream inputStream = new ByteArrayInputStream(param);
Class cls = clazz;
object = OBJENESIS_STD.newInstance((Class<T>) cls);
Schema schema = getSchema(cls);
ProtostuffIOUtil.mergeFrom(inputStream, object, schema);
return object;
} catch (Exception e) {
throw new MythException(e.getMessage(), e);
}
}
示例13: deserializeList
import com.dyuproject.protostuff.Schema; //导入依赖的package包/类
/**
* 反序列化列表
*
* @param paramArrayOfByte
* @param targetClass
* @return
*/
public static <T> List<T> deserializeList(byte[] paramArrayOfByte, Class<T> targetClass) {
if (paramArrayOfByte == null || paramArrayOfByte.length == 0) {
throw new RuntimeException("反序列化对象发生异常,byte序列为空!");
}
Schema<T> schema = RuntimeSchema.getSchema(targetClass);
List<T> result = null;
try {
result = ProtostuffIOUtil.parseListFrom(new ByteArrayInputStream(paramArrayOfByte), schema);
} catch (IOException e) {
throw new RuntimeException("反序列化对象列表发生异常!", e);
}
return result;
}
示例14: getSchema
import com.dyuproject.protostuff.Schema; //导入依赖的package包/类
private static Schema getSchema(Class<?> cls) throws IOException {
try {
return schemas.get(cls);
} catch (ExecutionException e) {
throw new IOException("create protostuff schema error", e);
}
}
示例15: serialize
import com.dyuproject.protostuff.Schema; //导入依赖的package包/类
public void serialize(OutputStream output, Object object) {
Class cls = (Class) object.getClass();
LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);
try {
Schema schema = getSchema(cls);
ProtostuffIOUtil.writeTo(output, object, schema, buffer);
} catch (Exception e) {
throw new IllegalStateException(e.getMessage(), e);
} finally {
buffer.clear();
}
}