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


Java LinkedBuffer类代码示例

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


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

示例1: serialize

import com.dyuproject.protostuff.LinkedBuffer; //导入依赖的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: serialize

import com.dyuproject.protostuff.LinkedBuffer; //导入依赖的package包/类
/**
 * 序列化对象
 *
 * @param obj 需要序更列化的对象
 * @return byte []
 * @throws TccException
 */
@Override
public byte[] serialize(Object obj) throws TccException {
    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 TccException(e.getMessage(), e);
    } finally {
        buffer.clear();
    }
    return outputStream.toByteArray();
}
 
开发者ID:yu199195,项目名称:happylifeplat-tcc,代码行数:23,代码来源:ProtostuffSerializer.java

示例3: serialize

import com.dyuproject.protostuff.LinkedBuffer; //导入依赖的package包/类
/**
 * 序列化对象
 *
 * @param obj 需要序更列化的对象
 * @return byte []
 * @throws MythException 异常信息
 */
@Override
public byte[] serialize(Object obj) throws MythException {
    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 MythException(e.getMessage(), e);
    } finally {
        buffer.clear();
    }
    return outputStream.toByteArray();
}
 
开发者ID:yu199195,项目名称:myth,代码行数:23,代码来源:ProtostuffSerializer.java

示例4: putSeckill

import com.dyuproject.protostuff.LinkedBuffer; //导入依赖的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

示例5: test1

import com.dyuproject.protostuff.LinkedBuffer; //导入依赖的package包/类
@Test
public void test1() {
    Schema<Person> personSchema = RuntimeSchema.createFrom(Person.class);
    Person person = new Person();
    person.setFirstName("firstName");
    person.setLastName("lastName");
    person.setEmail("[email protected]");
    Person person1 = new Person();
    person1.setFirstName("first");
    person1.setLastName("last");
    person1.setEmail("[email protected]");
    person.setPersons(Lists.newArrayList(person1));
    LinkedBuffer buffer = LinkedBuffer.allocate(1024);
    byte[] data = ProtobufIOUtil.toByteArray(person, personSchema, buffer);
    System.out.println(data);

    Person result = new Person();
    ProtobufIOUtil.mergeFrom(data, result, personSchema);
    System.out.println(result);
}
 
开发者ID:justimkiss,项目名称:bee,代码行数:21,代码来源:ProtostuffTest.java

示例6: putSeckill

import com.dyuproject.protostuff.LinkedBuffer; //导入依赖的package包/类
public String putSeckill(Seckill seckill) {
    // set Object(Seckill) -> 序列化 ->byte[]
    try {
        Jedis jedis = jedisPool.getResource();
        try {
            String key = "seckill:" + seckill.getSeckillId();
            byte[] bytes = ProtobufIOUtil.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) {
        logger.error(e.getMessage(), e);
    }
    return null;
}
 
开发者ID:firery,项目名称:imooc-seckill,代码行数:22,代码来源:RedisDao.java

示例7: mergeFrom

import com.dyuproject.protostuff.LinkedBuffer; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public <T> void mergeFrom(InputStream in, T obj, Schema<T> schema) throws IOException {
    try {
        JsonIOUtil.mergeFrom(in, obj, schema, _numeric, LinkedBuffer.allocate(getBufferSize()));
    } finally {
        if (isCloseEnabled()) {
            in.close();
        }
    }
}
 
开发者ID:jboss-switchyard,项目名称:switchyard,代码行数:14,代码来源:BaseJSONProtostuffSerializer.java

示例8: serialize

import com.dyuproject.protostuff.LinkedBuffer; //导入依赖的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();
    }
}
 
开发者ID:yu199195,项目名称:happylifeplat-transaction,代码行数:14,代码来源:ProtostuffSerialize.java

示例9: serialize

import com.dyuproject.protostuff.LinkedBuffer; //导入依赖的package包/类
/**
 * 序列化对象
 *
 * @param obj 需要序更列化的对象
 * @return byte []
 * @throws TransactionException
 */
@Override
public byte[] serialize(Object obj) throws TransactionException {
    Class cls = obj.getClass();
    LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);
    try ( ByteArrayOutputStream outputStream = new ByteArrayOutputStream();){
        Schema schema = getSchema(cls);
        ProtostuffIOUtil.writeTo(outputStream, obj, schema, buffer);
        return outputStream.toByteArray();
    } catch (Exception e) {
        throw new TransactionException(e.getMessage(), e);
    } finally {
        buffer.clear();
    }
}
 
开发者ID:yu199195,项目名称:happylifeplat-transaction,代码行数:22,代码来源:ProtostuffSerializer.java

示例10: serialize

import com.dyuproject.protostuff.LinkedBuffer; //导入依赖的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();
}
 
开发者ID:1991wangliang,项目名称:tx-lcn,代码行数:16,代码来源:ProtostuffSerializer.java

示例11: serialize

import com.dyuproject.protostuff.LinkedBuffer; //导入依赖的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

示例12: serialize

import com.dyuproject.protostuff.LinkedBuffer; //导入依赖的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

示例13: serialize

import com.dyuproject.protostuff.LinkedBuffer; //导入依赖的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

示例14: serialize

import com.dyuproject.protostuff.LinkedBuffer; //导入依赖的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();
    }
}
 
开发者ID:craware,项目名称:webapp-tyust,代码行数:13,代码来源:ProtostuffSerialize.java

示例15: serialize

import com.dyuproject.protostuff.LinkedBuffer; //导入依赖的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


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