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


Java LinkedBuffer.clear方法代码示例

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


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

示例3: 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

示例4: 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

示例5: 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

示例6: serialize

import io.protostuff.LinkedBuffer; //导入方法依赖的package包/类
@Override
public <T> byte[] serialize( final T source ) {
    @SuppressWarnings( "unchecked" )
    final Class<T> clazz = (Class<T>) source.getClass();
    final LinkedBuffer buffer = LinkedBuffer.allocate( LinkedBuffer.DEFAULT_BUFFER_SIZE );
    try {
        final Schema<T> schema = SchemaUtils.getSchema( clazz );
        return serializeInternal( source, schema, buffer );
    }
    catch ( final Exception e ) {
        throw new IllegalStateException( e );
    }
    finally {
        buffer.clear();
    }
}
 
开发者ID:srid99,项目名称:protostuff-example,代码行数:17,代码来源:AbstractProtoSerializer.java

示例7: serialize

import io.protostuff.LinkedBuffer; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
public <T> byte[] serialize(T object) {
	Schema<T> schema = getSchema((Class<T>)object.getClass());
	LinkedBuffer buffer = bufferThreadLocal.get();
	byte[] bytes;
	
	try {
		bytes = ProtostuffIOUtil.toByteArray(object, schema, buffer);
	} finally {
		buffer.clear();
	}
	
	return bytes;
}
 
开发者ID:DanceFirstThinkLater,项目名称:PetiteRPC,代码行数:15,代码来源:ProtostuffSerializer.java

示例8: convert

import io.protostuff.LinkedBuffer; //导入方法依赖的package包/类
@Override
public byte[] convert(T t) {
  final LinkedBuffer buffer = tl.get();
  try {
    return ProtostuffIOUtil.toByteArray(t, schema, buffer);
  } finally {
    buffer.clear();
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:10,代码来源:ProtostuffSerializer.java

示例9: serialize

import io.protostuff.LinkedBuffer; //导入方法依赖的package包/类
/**
 * 序列化
 *
 * @param obj
 * @param <T>
 * @return
 */
@SuppressWarnings("unchecked")
public static <T> byte[] serialize(T obj) {
    Class<T> clasz = (Class<T>) obj.getClass();
    LinkedBuffer buffer = LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE);
    try {
        Schema<T> schema = getSchema(clasz);
        return ProtostuffIOUtil.toByteArray(obj, schema, buffer);
    } catch (Exception e) {
        throw new IllegalStateException(e.getMessage(), e);
    } finally {
        buffer.clear();
    }
}
 
开发者ID:bobxwang,项目名称:springboot-scala-withswagger,代码行数:21,代码来源:ProtostufUtils.java

示例10: serialize

import io.protostuff.LinkedBuffer; //导入方法依赖的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 RpcFrameworkException(e.getMessage(), e);
    } finally {
        buffer.clear();
    }
}
 
开发者ID:netboynb,项目名称:coco,代码行数:17,代码来源:SerializationUtil.java

示例11: instantiateGlobalVar

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

		// ################ Serialization value ######################
		buffer.clear();
		objW = new ObjectWrap(instance);
		byte[] byI = ProtobufIOUtil.toByteArray(objW,scow, buffer);			
		// ################ Serialization value ######################
		
			JCL_message_global_var gvMessage = new MessageGlobalVarImpl(byK, byI);
			gvMessage.setType(10);
			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) {
		System.err
				.println("problem in JCL facade instantiateGlobalVar(String varName, Object instance)");
		return false;
	}
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:34,代码来源:JCL_FacadeImplLamb.java

示例12: instantiateGlobalVarReturn

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

		// ################ Serialization value ######################
		buffer.clear();
		objW = new ObjectWrap(instance);
		byte[] byI = ProtobufIOUtil.toByteArray(objW,scow, buffer);			
		// ################ Serialization value ######################


		
		    JCL_message_global_var gvMessage = new MessageGlobalVarImpl(byK, byI);
			gvMessage.setType(37);
			JCL_connector globalVarConnector = new ConnectorImpl();
			globalVarConnector.connect(host, Integer.parseInt(port),mac);
			JCL_result result = globalVarConnector.sendReceive(gvMessage,portS).getResult();				
			globalVarConnector.disconnect();
			
			// result from host
			return result.getCorrectResult();

	} catch (Exception e) {
		System.err
				.println("problem in JCL facade instantiateGlobalVar(String varName, Object instance)");
		return false;
	}
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:34,代码来源:JCL_FacadeImplLamb.java

示例13: sendReceive

import io.protostuff.LinkedBuffer; //导入方法依赖的package包/类
public void sendReceive(){
    try {
        Socket s = new Socket(ip, port);
        ObjectOutputStream out = new ObjectOutputStream(
                new BufferedOutputStream(s.getOutputStream()));

        Schema<MessageSensorImpl> schema = RuntimeSchema.getSchema(MessageSensorImpl.class);
        LinkedBuffer buffer = getApplicationBuffer();

        byte[] protostuff = null;
        try {
            protostuff = ProtostuffIOUtil.toByteArray(jcl_message, schema, buffer);
        } finally {
            buffer.clear();
        }

        out.writeObject(protostuff);
        out.flush();

        ObjectInputStream in = new ObjectInputStream(
                new BufferedInputStream(s.getInputStream()));
        String response = (String) in.readObject();

        System.err.println("client: " + response);

        in.close();
        out.close();
        s.close();

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

示例14: setValueUnlocking

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

		// ################ Serialization value ######################
		buffer.clear();
		objW = new ObjectWrap(instance);
		byte[] byI = ProtobufIOUtil.toByteArray(objW,scow, buffer);			
		// ################ Serialization value ######################


			JCL_message_global_var gvMessage = new MessageGlobalVarImpl(
					byK, byI);
			gvMessage.setType(13);
			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,代码行数:34,代码来源:JCL_FacadeImplLamb.java

示例15: instantiateGlobalVar

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

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

		// ################ Serialization value ######################
		buffer.clear();
		objW = new ObjectWrap(instance);
		byte[] byI = ProtobufIOUtil.toByteArray(objW,scow, buffer);
		// ################ Serialization value ######################

		JCL_message_global_var gvMessage = new MessageGlobalVarImpl(byK, byI);
		gvMessage.setType(10);
		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) {
		System.err
				.println("problem in JCL facade instantiateGlobalVar(String varName, Object instance)");
		return false;
	}
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:34,代码来源:JCL_FacadeImplLamb.java


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