• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java LinkedBuffer类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: serialize

import io.protostuff.LinkedBuffer; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public static <T> byte[] serialize(T obj) {
    Class<T> cls = (Class<T>) obj.getClass();

    // 如果是基本类型,则转换为string
    if (isSupport(cls)) {
        return castToString(obj).getBytes();
    }

    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:TwoDragonLake,项目名称:tdl-seckill,代码行数:20,代码来源:ConvertUtil.java


示例2: write

import io.protostuff.LinkedBuffer; //导入依赖的package包/类
public void write(WrapSchema headerSchema, Object header, WrapSchema bodySchema, Object body) throws Exception {
  // 写protobuf数据
  LinkedBuffer linkedBuffer = LinkedBuffer.allocate();
  ProtobufOutput output = new ProtobufOutput(linkedBuffer);

  // 写header
  if (headerSchema != null) {
    headerSchema.writeObject(output, header, protobufFeature);
  }
  int headerSize = output.getSize();

  // 写body
  // void时bodySchema为null
  if (bodySchema != null) {
    bodySchema.writeObject(output, body, protobufFeature);
  }

  writeLength(output.getSize(), headerSize);
  LinkedBuffer.writeTo(this, linkedBuffer);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:21,代码来源:HighwayOutputStream.java


示例3: testWriteObject

import io.protostuff.LinkedBuffer; //导入依赖的package包/类
@Test
public void testWriteObject() {
  boolean status = true;
  LinkedBuffer linkedBuffer = LinkedBuffer.allocate();
  ProtobufOutput output = new ProtobufOutput(linkedBuffer);
  String[] stringArray = new String[1];
  stringArray[0] = "abc";

  MultiWrapper multiWrapper = Mockito.mock(MultiWrapper.class);
  Mockito.when(schema.newMessage()).thenReturn(multiWrapper);
  try {
    argsWrapSchema.writeObject(output, stringArray);
  } catch (IOException e) {
    status = true;
  }
  Assert.assertTrue(status);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:18,代码来源:TestArgsWrapSchema.java


示例4: serialize

import io.protostuff.LinkedBuffer; //导入依赖的package包/类
/**
 * 序列化对象
 *
 * @param obj
 * @param <T>
 * @return
 */
public static <T> byte[] serialize(T obj) {
    if (obj == null) {
        throw new RuntimeException("序列化对象(" + obj + ")为空!");
    }
    RuntimeSchema<T> schema = RuntimeSchema.createFrom((Class<T>) 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:lupindong,项目名称:xq_seckill_microservice,代码行数:24,代码来源:ProtoStuffUtil.java


示例5: putEmp

import io.protostuff.LinkedBuffer; //导入依赖的package包/类
/**
 * 将emp存入redis
 * @param emp
 * @return
 * @throws Exception
 */
private String putEmp(Emp emp) throws Exception{
    Jedis jedis = jedisPool.getResource();
    jedis.auth("redis");
    try {
        String key = "emp" + emp.getEmpId();
        byte[] bytes = ProtobufIOUtil.toByteArray(emp, schema,
                LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE));
        int timeout = 60 * 60;//1小时
        String result = jedis.setex(key.getBytes(), timeout, bytes);

        return result;
    }finally {
        jedis.close();
    }

}
 
开发者ID:chris-zh,项目名称:feeler,代码行数:23,代码来源:JedisTest.java


示例6: getValueLocking

import io.protostuff.LinkedBuffer; //导入依赖的package包/类
public Object getValueLocking(Object key,String host,String port, String mac, String portS,int hostId) {
	try {

			// ################ Serialization key ########################
			LinkedBuffer buffer = LinkedBuffer.allocate(1048576);
			ObjectWrap objW = new ObjectWrap(key);					
			key = ProtobufIOUtil.toByteArray(objW,scow, buffer);			
			// ################ Serialization key ########################

			JCL_message_generic gvMessage = new MessageGenericImpl();
			gvMessage.setType(15);
			gvMessage.setRegisterData(key);
			JCL_connector globalVarConnector = new ConnectorImpl();
			globalVarConnector.connect(host,Integer.parseInt(port),mac);
			JCL_message_generic result = (JCL_message_generic) globalVarConnector.sendReceiveG(gvMessage,portS);
			globalVarConnector.disconnect();

			// result from host
			return result.getRegisterData();

	} catch (Exception e) {
		System.err.println("problem in JCL facade getValueLocking");
		e.printStackTrace();
		return null;
	}
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:27,代码来源:JCL_FacadeImplLamb.java


示例7: isLock

import io.protostuff.LinkedBuffer; //导入依赖的package包/类
public Boolean isLock(Object key,String host,String port, String mac, String portS, int hostId) {
	try {
			
			// ################ Serialization key ########################
			LinkedBuffer buffer = LinkedBuffer.allocate(1048576);
			ObjectWrap objW = new ObjectWrap(key);					
			key = ProtobufIOUtil.toByteArray(objW,scow, buffer);			
			// ################ Serialization key ########################

			JCL_message_generic gvMessage = new MessageGenericImpl();
			gvMessage.setRegisterData(key);
			gvMessage.setType(20);
			JCL_connector globalVarConnector = new ConnectorImpl();
			globalVarConnector.connect(host, Integer.parseInt(port),mac);
			JCL_result result = globalVarConnector.sendReceive(gvMessage,portS)
					.getResult();
			Boolean b = (Boolean) result.getCorrectResult();
			globalVarConnector.disconnect();
			
			// result from host
			return b;

	} catch (Exception e) {
		return false;
	}
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:27,代码来源:JCL_FacadeImplLamb.java


示例8: put

import io.protostuff.LinkedBuffer; //导入依赖的package包/类
/**
  * Associates the specified value with the specified key in this map.
  * If the map previously contained a mapping for the key, the old
  * value is replaced.
  *
  * @param key key with which the specified value is to be associated
  * @param value value to be associated with the specified key
  * @return the previous value associated with <tt>key</tt>, or
  *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
  */    
 public V put(K key, V value){
 	Object oldValue = null;
     if ((key != null) && ((oldValue = super.hashPut((key.toString()+"�Map�"+gvName), value))!=null)){        	
     		        	
// ################ Serialization key ########################
LinkedBuffer buffer = LinkedBuffer.allocate(1048576);
ObjectWrap objW = new ObjectWrap(key);	
Schema<ObjectWrap> scow = RuntimeSchema.getSchema(ObjectWrap.class);
byte[] k = ProtobufIOUtil.toByteArray(objW,scow, buffer);			
// ################ Serialization key ########################

     	super.hashAdd(gvName,ByteBuffer.wrap(k),idLocalize);
     }else{
    	 System.out.println("Null key or fault in put<K,V> on cluster!");
     }
     
     return (V)oldValue;
 }
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:29,代码来源:JCLHashMapPacu.java


示例9: putUnlock

import io.protostuff.LinkedBuffer; //导入依赖的package包/类
/**
 * Associates the specified value with the specified key in this map.
 * If the map previously contained a mapping for the key, the old
 * value is replaced.
 *
 * @param key key with which the specified value is to be associated
 * @param value value to be associated with the specified key
 * @return the previous value associated with <tt>key</tt>, or
 *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
 */

public V putUnlock(K key, V value){
	V oldValue = null;
    if (key != null){        	
    	if(DEFAULT_JCL.containsGlobalVar(key.toString()+"�Map�"+gvName)){
    		oldValue = (V) DEFAULT_JCL.getValue(key.toString()+"�Map�"+gvName).getCorrectResult();
    		DEFAULT_JCL.setValueUnlocking((key.toString()+"�Map�"+gvName), value);
    	}else if (DEFAULT_JCL.instantiateGlobalVar((key.toString()+"�Map�"+gvName), value)){
			
			// ################ Serialization key ########################
			LinkedBuffer buffer = LinkedBuffer.allocate(1048576);
			ObjectWrap objW = new ObjectWrap(key);	
			Schema scow = RuntimeSchema.getSchema(ObjectWrap.class);
			byte[] k = ProtobufIOUtil.toByteArray(objW,scow, buffer);			
			// ################ Serialization key ########################

    		super.hashAdd(gvName,ByteBuffer.wrap(k),idLocalize);
		}
    }else{
   	 System.out.println("Can't put<K,V> with null key!");
    }        
    return (oldValue == null ? null : oldValue);
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:34,代码来源:JCLHashMapPacu.java


示例10: putAll

import io.protostuff.LinkedBuffer; //导入依赖的package包/类
/**
   * Copies all of the mappings from the specified map to this map.
   * These mappings will replace any mappings that this map had for
   * any of the keys currently in the specified map.
   *
   * @param m mappings to be stored in this map
   * @throws NullPointerException if the specified map is null
   */
  public void putAll(Map<? extends K, ? extends V> m) {
      int numKeysToBeAdded = m.size();
              
      if (numKeysToBeAdded == 0)
          return;
      super.instantiateBin((Object)m.entrySet(), this.gvName);
              
      List<Object> obj =  new ArrayList<Object>();
LinkedBuffer buffer = LinkedBuffer.allocate(1048576);

      for(K key:m.keySet()){
      	
	// ################ Serialization key ########################
	buffer.clear();
      	ObjectWrap objW = new ObjectWrap(key);	
	Schema scow = RuntimeSchema.getSchema(ObjectWrap.class);
	byte[] k = ProtobufIOUtil.toByteArray(objW,scow, buffer);			
	// ################ Serialization key ########################

      	obj.add(ByteBuffer.wrap(k));
      }   
      
      super.hashAdd(gvName, obj,idLocalize);                
  }
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:33,代码来源:JCLHashMapPacu.java


示例11: getValueLocking

import io.protostuff.LinkedBuffer; //导入依赖的package包/类
public Object getValueLocking(Object key,String host,String port, String mac, String portS,int hostId) {
	try {

		// ################ Serialization key ########################
		LinkedBuffer buffer = LinkedBuffer.allocate(1048576);
		ObjectWrap objW = new ObjectWrap(key);
		key = ProtobufIOUtil.toByteArray(objW,scow, buffer);
		// ################ Serialization key ########################

		JCL_message_generic gvMessage = new MessageGenericImpl();
		gvMessage.setType(15);
		gvMessage.setRegisterData(key);
		JCL_connector globalVarConnector = new ConnectorImpl();
		globalVarConnector.connect(host,Integer.parseInt(port),mac);
		JCL_message_generic result = (JCL_message_generic) globalVarConnector.sendReceiveG(gvMessage,portS);
		globalVarConnector.disconnect();

		// result from host
		return result.getRegisterData();

	} catch (Exception e) {
		System.err.println("problem in JCL facade getValueLocking");
		e.printStackTrace();
		return null;
	}
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:27,代码来源:JCL_FacadeImplLamb.java


示例12: isLock

import io.protostuff.LinkedBuffer; //导入依赖的package包/类
public Boolean isLock(Object key,String host,String port, String mac, String portS, int hostId) {
	try {

		// ################ Serialization key ########################
		LinkedBuffer buffer = LinkedBuffer.allocate(1048576);
		ObjectWrap objW = new ObjectWrap(key);
		key = ProtobufIOUtil.toByteArray(objW,scow, buffer);
		// ################ Serialization key ########################

		JCL_message_generic gvMessage = new MessageGenericImpl();
		gvMessage.setRegisterData(key);
		gvMessage.setType(20);
		JCL_connector globalVarConnector = new ConnectorImpl();
		globalVarConnector.connect(host, Integer.parseInt(port),mac);
		JCL_result result = globalVarConnector.sendReceive(gvMessage,portS)
				.getResult();
		Boolean b = (Boolean) result.getCorrectResult();
		globalVarConnector.disconnect();

		// result from host
		return b;

	} catch (Exception e) {
		return false;
	}
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:27,代码来源:JCL_FacadeImplLamb.java


示例13: put

import io.protostuff.LinkedBuffer; //导入依赖的package包/类
/**
 * Associates the specified value with the specified key in this map.
 * If the map previously contained a mapping for the key, the old
 * value is replaced.
 *
 * @param key key with which the specified value is to be associated
 * @param value value to be associated with the specified key
 * @return the previous value associated with <tt>key</tt>, or
 *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
 */
public V put(K key, V value){
    Object oldValue = null;
    if ((key != null) && ((oldValue = super.hashPut((key.toString()+"¬Map¬"+gvName), value))!=null)){

        // ################ Serialization key ########################
        LinkedBuffer buffer = LinkedBuffer.allocate(1048576);
        ObjectWrap objW = new ObjectWrap(key);
        Schema<ObjectWrap> scow = RuntimeSchema.getSchema(ObjectWrap.class);
        byte[] k = ProtobufIOUtil.toByteArray(objW,scow, buffer);
        // ################ Serialization key ########################

        super.hashAdd(gvName,ByteBuffer.wrap(k),idLocalize);
    }else{
        System.out.println("Null key or fault in put<K,V> on cluster!");
    }

    return (V)oldValue;
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:29,代码来源:JCLHashMapPacu.java


示例14: putUnlock

import io.protostuff.LinkedBuffer; //导入依赖的package包/类
/**
 * Associates the specified value with the specified key in this map.
 * If the map previously contained a mapping for the key, the old
 * value is replaced.
 *
 * @param key key with which the specified value is to be associated
 * @param value value to be associated with the specified key
 * @return the previous value associated with <tt>key</tt>, or
 *         <tt>null</tt> if there was no mapping for <tt>key</tt>.
 */

public V putUnlock(K key, V value){
    V oldValue = null;
    if (key != null){
        if(DEFAULT_JCL.containsGlobalVar(key.toString()+"¬Map¬"+gvName)){
            oldValue = (V) DEFAULT_JCL.getValue(key.toString()+"¬Map¬"+gvName).getCorrectResult();
            DEFAULT_JCL.setValueUnlocking((key.toString()+"¬Map¬"+gvName), value);
        }else if (DEFAULT_JCL.instantiateGlobalVar((key.toString()+"¬Map¬"+gvName), value)){

            // ################ Serialization key ########################
            LinkedBuffer buffer = LinkedBuffer.allocate(1048576);
            ObjectWrap objW = new ObjectWrap(key);
            Schema scow = RuntimeSchema.getSchema(ObjectWrap.class);
            byte[] k = ProtobufIOUtil.toByteArray(objW,scow, buffer);
            // ################ Serialization key ########################

            super.hashAdd(gvName,ByteBuffer.wrap(k),idLocalize);
        }
    }else{
        System.out.println("Can't put<K,V> with null key!");
    }
    return (oldValue == null ? null : oldValue);
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:34,代码来源:JCLHashMapPacu.java


示例15: putAll

import io.protostuff.LinkedBuffer; //导入依赖的package包/类
/**
 * Copies all of the mappings from the specified map to this map.
 * These mappings will replace any mappings that this map had for
 * any of the keys currently in the specified map.
 *
 * @param m mappings to be stored in this map
 * @throws NullPointerException if the specified map is null
 */
public void putAll(Map<? extends K, ? extends V> m) {
    int numKeysToBeAdded = m.size();

    if (numKeysToBeAdded == 0)
        return;
    super.instantiateBin((Object)m.entrySet(), this.gvName);

    List<Object> obj =  new ArrayList<Object>();
    LinkedBuffer buffer = LinkedBuffer.allocate(1048576);

    for(K key:m.keySet()){

        // ################ Serialization key ########################
        buffer.clear();
        ObjectWrap objW = new ObjectWrap(key);
        Schema scow = RuntimeSchema.getSchema(ObjectWrap.class);
        byte[] k = ProtobufIOUtil.toByteArray(objW,scow, buffer);
        // ################ Serialization key ########################

        obj.add(ByteBuffer.wrap(k));
    }

    super.hashAdd(gvName, obj,idLocalize);
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:33,代码来源:JCLHashMapPacu.java


示例16: getData

import io.protostuff.LinkedBuffer; //导入依赖的package包/类
public byte[] getData () {
    byte[] rtnData = null;
    if (rawData) {
        return data;
    } else {
        //auto-serialize
        LinkedBuffer buffer = getMessageBuffer ();
        Schema<MessageT> schema = (Schema<MessageT>) RuntimeSchema.getSchema (getClass ());
        MessageT message = (MessageT) this;
        try {
            rtnData = ProtostuffIOUtil.toByteArray (message, schema, buffer);
        } finally {
            buffer.clear ();
        }
    }

    return rtnData;
}
 
开发者ID:BFergerson,项目名称:Beam,代码行数:19,代码来源:BeamMessage.java


示例17: testGraph

import io.protostuff.LinkedBuffer; //导入依赖的package包/类
public void testGraph()
{
    System.err.println(RuntimeEnv.COLLECTION_SCHEMA_ON_REPEATED_FIELDS);

    Bean bean = fill(new Bean());

    verify(bean);

    Schema<Bean> schema = RuntimeSchema.getSchema(Bean.class);
    // print(schema);
    byte[] bytes = GraphIOUtil.toByteArray(bean, schema,
            LinkedBuffer.allocate(256));

    Bean deBean = new Bean();
    GraphIOUtil.mergeFrom(bytes, deBean, schema);

    verify(deBean);
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:19,代码来源:ObjectSchemaTest.java


示例18: testSimpleTask

import io.protostuff.LinkedBuffer; //导入依赖的package包/类
@Test
public void testSimpleTask() throws Exception
{
    Schema<Task> schema = RuntimeSchema.getSchema(Task.class);

    Task p = filledTask();

    byte[] data = ProtostuffIOUtil.toByteArray(p, schema,
            LinkedBuffer.allocate(512));

    Task p2 = new Task();
    ProtostuffIOUtil.mergeFrom(data, p2, schema);
    // System.err.println(p2);

    assertEquals(p, p2);
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:17,代码来源:CollectionTest.java


示例19: testITask

import io.protostuff.LinkedBuffer; //导入依赖的package包/类
@Test
public void testITask() throws Exception
{
    // Because we mapped ITask to Task, this is ok.
    Schema<ITask> schema = RuntimeSchema.getSchema(ITask.class);

    ITask p = filledTask();

    byte[] data = ProtostuffIOUtil.toByteArray(p, schema,
            LinkedBuffer.allocate(512));

    ITask p2 = new Task();
    ProtostuffIOUtil.mergeFrom(data, p2, schema);
    // System.err.println(p2);

    assertEquals(p, p2);
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:18,代码来源:CollectionTest.java


示例20: testEmployee

import io.protostuff.LinkedBuffer; //导入依赖的package包/类
@Test
public void testEmployee() throws Exception
{
    Schema<Employee> schema = RuntimeSchema.getSchema(Employee.class);

    Employee p = filledEmployee();

    byte[] data = ProtostuffIOUtil.toByteArray(p, schema,
            LinkedBuffer.allocate(512));

    Employee p2 = new Employee();
    ProtostuffIOUtil.mergeFrom(data, p2, schema);
    // System.err.println(p2);

    assertEquals(p, p2);
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:17,代码来源:CollectionTest.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java BlockFlowerPot类代码示例发布时间:2022-05-21
下一篇:
Java ConnectionEventListener类代码示例发布时间:2022-05-21
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap