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


Java LinkedBuffer.allocate方法代码示例

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


在下文中一共展示了LinkedBuffer.allocate方法的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: 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: 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

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

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

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

示例10: createBuffer

import io.protostuff.LinkedBuffer; //导入方法依赖的package包/类
protected Buffer createBuffer(WrapSchema schema, Object value) throws Exception {
  Buffer headerBuffer;
  LinkedBuffer linkedBuffer = LinkedBuffer.allocate();
  ProtobufOutput output = new ProtobufOutput(linkedBuffer);
  schema.writeObject(output, value);
  try (BufferOutputStream os = new BufferOutputStream()) {
    LinkedBuffer.writeTo(os, linkedBuffer);

    headerBuffer = os.getBuffer();
  }
  return headerBuffer;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:13,代码来源:TestHighwayServerConnection.java

示例11: toByteArray

import io.protostuff.LinkedBuffer; //导入方法依赖的package包/类
private byte[] toByteArray(WrapSchema schema, Object value) throws Exception {
  LinkedBuffer linkedBuffer = LinkedBuffer.allocate();
  ProtobufOutput output = new ProtobufOutput(linkedBuffer);

  schema.writeObject(output, value);
  return output.toByteArray();
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:8,代码来源:TestProtobufSchemaUtils.java

示例12: object

import io.protostuff.LinkedBuffer; //导入方法依赖的package包/类
@Test
public void object() throws Exception {
  WrapSchema schema = ProtobufSchemaUtils.getOrCreateSchema(Object.class);

  LinkedBuffer linkedBuf = LinkedBuffer.allocate();
  ProtobufOutput output = new ProtobufOutput(linkedBuf);
  schema.writeObject(output, 1);

  Input input = new ByteArrayInput(output.toByteArray(), false);
  Object result = schema.readObject(input);

  Assert.assertEquals(1, result);
  Assert.assertThat(result, Matchers.instanceOf(Integer.class));
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:15,代码来源:TestProtobufSchemaUtils.java

示例13: 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];
  try {
    argsNotWrapSchema.writeObject(output, stringArray);
  } catch (Exception e) {
    status = false;
  }
  Assert.assertTrue(status);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:14,代码来源:TestArgsNotWrapSchema.java

示例14: testWriteObjectToSchema

import io.protostuff.LinkedBuffer; //导入方法依赖的package包/类
@Test
public void testWriteObjectToSchema() {
  boolean status = true;
  LinkedBuffer linkedBuffer = LinkedBuffer.allocate();
  ProtobufOutput output = new ProtobufOutput(linkedBuffer);
  String[] stringArray = new String[1];
  stringArray[0] = "abc";
  try {
    argsNotWrapSchema.writeObject(output, stringArray);
  } catch (Exception e) {
    status = false;
  }
  Assert.assertTrue(status);
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:15,代码来源:TestArgsNotWrapSchema.java

示例15: testProtostuff

import io.protostuff.LinkedBuffer; //导入方法依赖的package包/类
protected byte[] testProtostuff(Map<String, String> map, Map<String, User> userMap) throws IOException {
  ProtobufCompatibleUtils.init();

  RuntimeSchema<ModelProtostuff> schema = RuntimeSchema.createFrom(ModelProtostuff.class);
  ModelProtostuff model = new ModelProtostuff();

  model.setContext(map);
  model.setUserMap(userMap);
  model.getList().add("l1");
  model.getList().add("l2");

  LinkedBuffer linkedBuffer = LinkedBuffer.allocate();
  ProtobufOutput output = new ProtobufOutput(linkedBuffer);
  ProtobufFeature protobufFeature = new ProtobufFeature();
  protobufFeature.setUseProtobufMapCodec(true);

  ProtobufFeatureUtils.setProtobufFeature(protobufFeature);
  schema.writeTo(output, model);

  ByteArrayOutputStream s = new ByteArrayOutputStream();
  LinkedBuffer.writeTo(s, linkedBuffer);
  byte[] bytes = s.toByteArray();

  ModelProtostuff newModel = new ModelProtostuff();
  ByteArrayInput bai = new ByteArrayInput(bytes, false);

  schema.mergeFrom(bai, newModel);

  ProtobufFeatureUtils.removeProtobufFeature();
  Assert.assertEquals("v1", newModel.getContext().get("k1"));
  Assert.assertEquals("v2", newModel.getContext().get("k2"));
  Assert.assertEquals("n1", newModel.getUserMap().get("u1").getName());
  Assert.assertEquals("n2", newModel.getUserMap().get("u2").getName());
  Assert.assertEquals("l1", newModel.getList().get(0));
  Assert.assertEquals("l2", newModel.getList().get(1));

  return bytes;
}
 
开发者ID:apache,项目名称:incubator-servicecomb-java-chassis,代码行数:39,代码来源:TestProtobufCompatibleUtils.java


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