当前位置: 首页>>代码示例>>Java>>正文


Java ProtostuffIOUtil.toByteArray方法代码示例

本文整理汇总了Java中com.dyuproject.protostuff.ProtostuffIOUtil.toByteArray方法的典型用法代码示例。如果您正苦于以下问题:Java ProtostuffIOUtil.toByteArray方法的具体用法?Java ProtostuffIOUtil.toByteArray怎么用?Java ProtostuffIOUtil.toByteArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.dyuproject.protostuff.ProtostuffIOUtil的用法示例。


在下文中一共展示了ProtostuffIOUtil.toByteArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: serialize

import com.dyuproject.protostuff.ProtostuffIOUtil; //导入方法依赖的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;
}
 
开发者ID:melonlee,项目名称:PowerApi,代码行数:24,代码来源:ProtoStuffSerializerUtil.java

示例2: putSeckill

import com.dyuproject.protostuff.ProtostuffIOUtil; //导入方法依赖的package包/类
public String putSeckill(Seckill seckill) {
    try {
        Jedis jedis = jedisPool.getResource();
        try {
            String key = "seckill:" + seckill.getSeckillId();
            byte[] bytes = ProtostuffIOUtil.toByteArray(seckill, schema,
                    LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE));
            int timeout = 60 * 60; //一小时
            String result = jedis.setex(key.getBytes(), timeout, bytes);
            return result;
        } finally{
            jedis.close();
        }
    } catch (Exception e) {
        LOG.error(e.getMessage(), e);
    }
    return null;
}
 
开发者ID:jessezwd,项目名称:HCS,代码行数:19,代码来源:RedisDao.java

示例3: serialize

import com.dyuproject.protostuff.ProtostuffIOUtil; //导入方法依赖的package包/类
public byte[] serialize(Object object) {
	if(object == null){
		return null;
	}
	LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);
	try {
		//return ProtobufIOUtil.toByteArray(new ObjectWrapper(object), schema, buffer);
		return ProtostuffIOUtil.toByteArray(new ObjectWrapper(object), schema, buffer);
	} finally {
		buffer.clear();
	}
}
 
开发者ID:penggle,项目名称:xproject,代码行数:13,代码来源:ProtostuffSerializer.java

示例4: serialize

import com.dyuproject.protostuff.ProtostuffIOUtil; //导入方法依赖的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();
    }
}
 
开发者ID:linuer,项目名称:nan,代码行数:13,代码来源:ProtoStuffSerializer.java

示例5: serialize

import com.dyuproject.protostuff.ProtostuffIOUtil; //导入方法依赖的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();
    }
}
 
开发者ID:TFdream,项目名称:mango,代码行数:12,代码来源:ProtostuffSerializer.java

示例6: serialize

import com.dyuproject.protostuff.ProtostuffIOUtil; //导入方法依赖的package包/类
@Override
public <T> byte[] serialize(T obj) throws IOException {
	Class cls = 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 IllegalStateException(e.getMessage(), e);
       } finally {
           buffer.clear();
       }
	
}
 
开发者ID:chenxh,项目名称:rpc,代码行数:15,代码来源:ProtostuffSerialization.java

示例7: serialize

import com.dyuproject.protostuff.ProtostuffIOUtil; //导入方法依赖的package包/类
@Override
public byte[] serialize(Object obj) throws  SerializationException {
    LinkedBuffer buffer = LinkedBuffer.allocate(1024);
    try {
        Schema schema = getSchema(obj.getClass());
        return ProtostuffIOUtil.toByteArray(obj, schema, buffer);
    } catch (Throwable e) {
        throw new SerializationException(e.getMessage(), e);
    } finally {
        buffer.clear();
    }
}
 
开发者ID:justimkiss,项目名称:bee,代码行数:13,代码来源:ProtostuffSerializer.java

示例8: serialize

import com.dyuproject.protostuff.ProtostuffIOUtil; //导入方法依赖的package包/类
@Override
public <T> byte[] serialize(T obj) {
   	@SuppressWarnings("unchecked")
	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 IllegalStateException(e.getMessage(), e);
       } finally {
           buffer.clear();
       }
}
 
开发者ID:xuxueli,项目名称:xxl-incubator,代码行数:15,代码来源:ProtostuffSerializer.java

示例9: toBinary

import com.dyuproject.protostuff.ProtostuffIOUtil; //导入方法依赖的package包/类
@Override
public byte[] toBinary(Object o)
{
  Schema schema = RuntimeSchema.getSchema(o.getClass());
  LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);
  byte[] protostuff = ProtostuffIOUtil.toByteArray(o, schema, buffer);
  return protostuff;
}
 
开发者ID:beykery,项目名称:bakka,代码行数:9,代码来源:BakkaSerializer.java

示例10: encode

import com.dyuproject.protostuff.ProtostuffIOUtil; //导入方法依赖的package包/类
@Override
protected void encode(ChannelHandlerContext ctx, Object msg, ByteBuf out) throws Exception {

    LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);
    try {
        Schema<T> schema = SchemaCache.getSchema(type);
        byte[] arr = ProtostuffIOUtil.toByteArray((T)msg, schema, buffer);
        out.writeBytes(arr);
    } finally {
        buffer.clear();
    }

}
 
开发者ID:TFdream,项目名称:netty-tutorials,代码行数:14,代码来源:RpcEncoder.java

示例11: encode

import com.dyuproject.protostuff.ProtostuffIOUtil; //导入方法依赖的package包/类
@Override
public byte[] encode(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();
    }
}
 
开发者ID:TFdream,项目名称:netty-tutorials,代码行数:12,代码来源:ProtostuffSerializer.java

示例12: serialize

import com.dyuproject.protostuff.ProtostuffIOUtil; //导入方法依赖的package包/类
/**
 * 序列化(对象 --> 字节数组)
 */
@SuppressWarnings("uncheched")
public static <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 IllegalStateException(e.getMessage(),e);
    }finally {
        buffer.clear();
    }
}
 
开发者ID:liuhangyang,项目名称:StormMQ,代码行数:17,代码来源:Tool.java

示例13: serialize

import com.dyuproject.protostuff.ProtostuffIOUtil; //导入方法依赖的package包/类
/**
 * 序列化(对象 -> 字节数组)
 */
@SuppressWarnings("unchecked")
public static <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 IllegalStateException(e.getMessage(), e);
    } finally {
        buffer.clear();
    }
}
 
开发者ID:zoopaper,项目名称:rpc4j,代码行数:17,代码来源:SerializationUtil.java

示例14: object2Bytes

import com.dyuproject.protostuff.ProtostuffIOUtil; //导入方法依赖的package包/类
/**
 * 对象转换成字节数组
 * @param obj 目标对象
 * @param <T>
 * @return
 */
public static <T> byte[] object2Bytes(T obj) {
    if (obj == null) {
        return ArrayUtils.EMPTY_BYTE_ARRAY;
    }

    Class<T> clazz = (Class<T>) obj.getClass();
    Schema<T> schema = RuntimeSchema.getSchema(clazz);

    LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);
    return ProtostuffIOUtil.toByteArray(obj, schema, buffer);
}
 
开发者ID:Jakegogo,项目名称:concurrent,代码行数:18,代码来源:ProtostuffUtils.java

示例15: serializeInternal

import com.dyuproject.protostuff.ProtostuffIOUtil; //导入方法依赖的package包/类
private <T> byte[] serializeInternal(final T source, final Schema<T> schema, final LinkedBuffer buffer) {
    return ProtostuffIOUtil.toByteArray(source, schema, buffer);
}
 
开发者ID:sohutv,项目名称:cachecloud,代码行数:4,代码来源:ProtostuffSerializer.java


注:本文中的com.dyuproject.protostuff.ProtostuffIOUtil.toByteArray方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。