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


Java ProtobufIOUtil.toByteArray方法代码示例

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


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

示例1: asFileConfig

import io.protostuff.ProtobufIOUtil; //导入方法依赖的package包/类
@JsonIgnore
@SuppressWarnings({ "rawtypes", "unchecked" })
public FileConfig asFileConfig() {
  buffer.clear();
  FileConfig fc = new FileConfig();
  fc.setType(getFileType());
  fc.setName(name);
  fc.setOwner(owner);
  fc.setCtime(ctime);
  fc.setType(getFileType());
  fc.setVersion(getVersion());
  fc.setLocation(location);
  byte[] bytes = ProtobufIOUtil.toByteArray(this, (Schema) getPrivateSchema(), buffer);
  fc.setExtendedConfig(ByteString.copyFrom(bytes));
  fc.setFullPathList(fullPath);
  return fc;
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:18,代码来源:FileFormat.java

示例2: isLock

import io.protostuff.ProtobufIOUtil; //导入方法依赖的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

示例3: putAll

import io.protostuff.ProtobufIOUtil; //导入方法依赖的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: WriteObjectOnSock

import io.protostuff.ProtobufIOUtil; //导入方法依赖的package包/类
protected void WriteObjectOnSock(JCL_message obj,byte[] add,JCL_handler handler, boolean complete) throws Exception {

        //Write data
        @SuppressWarnings("unchecked")
        byte[] Out = ProtobufIOUtil.toByteArray(obj, Constants.Serialization.schema[obj.getMsgType()], buffer.get());
        buffer.get().clear();
        byte key = (byte) obj.getMsgType();

        ByteArrayOutputStream outputStream = new ByteArrayOutputStream( );
        outputStream.write(Out);
        outputStream.write(add);

        byte send[] = outputStream.toByteArray( );
        handler.send(send,key,complete);
        //End Write data
    }
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:17,代码来源:GenericConsumer.java

示例5: getValueLocking

import io.protostuff.ProtobufIOUtil; //导入方法依赖的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

示例6: testProtobuf

import io.protostuff.ProtobufIOUtil; //导入方法依赖的package包/类
public void testProtobuf() throws Exception
{
    Schema<Zoo> schema = RuntimeSchema.getSchema(Zoo.class);
    Zoo p = filledZoo();

    byte[] data = ProtobufIOUtil.toByteArray(p, schema, buf());
    // System.err.println("protobuf: " + data.length);

    Zoo p2 = new Zoo();
    ProtobufIOUtil.mergeFrom(data, p2, schema);

    assertEquals(p, p2);

    List<Zoo> list = new ArrayList<Zoo>();
    list.add(p);
    list.add(p2);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ProtobufIOUtil.writeListTo(out, list, schema, buf());
    byte[] listData = out.toByteArray();

    ByteArrayInputStream in = new ByteArrayInputStream(listData);
    List<Zoo> parsedList = ProtobufIOUtil.parseListFrom(in, schema);

    assertEquals(list, parsedList);
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:27,代码来源:PolymorphicSerializationTest.java

示例7: testProtobuf

import io.protostuff.ProtobufIOUtil; //导入方法依赖的package包/类
public void testProtobuf() throws Exception
{
    Schema<Entity> schema = RuntimeSchema.getSchema(Entity.class);
    Entity p = filledEntity();

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

    Entity p2 = new Entity();
    ProtostuffIOUtil.mergeFrom(data, p2, schema);

    assertEquals(p, p2);

    List<Entity> list = new ArrayList<Entity>();
    list.add(p);
    list.add(p2);

    ByteArrayOutputStream out = new ByteArrayOutputStream();
    ProtobufIOUtil.writeListTo(out, list, schema, buf());
    byte[] listData = out.toByteArray();

    ByteArrayInputStream in = new ByteArrayInputStream(listData);
    List<Entity> parsedList = ProtobufIOUtil.parseListFrom(in, schema);

    assertEquals(list, parsedList);
}
 
开发者ID:protostuff,项目名称:protostuff,代码行数:27,代码来源:DateTest.java

示例8: toPB

import io.protostuff.ProtobufIOUtil; //导入方法依赖的package包/类
static CoordinationProtos.NodeEndpoint toPB(NodeEndpoint stuf) {
  // TODO use schemas to do this...
  LinkedBuffer buffer = LinkedBuffer.allocate();
  byte[] bytes = ProtobufIOUtil.toByteArray(stuf, stuf.cachedSchema(), buffer);
  try {
    return CoordinationProtos.NodeEndpoint.PARSER.parseFrom(bytes);
  } catch (InvalidProtocolBufferException e) {
    throw new IllegalArgumentException("Cannot convert from protostuff to protobuf");
  }
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:11,代码来源:JobsServiceUtil.java

示例9: toByteString

import io.protostuff.ProtobufIOUtil; //导入方法依赖的package包/类
public ByteString toByteString() {
  @SuppressWarnings("unchecked")
  Schema<Source> schema = (Schema<Source>) SourceDefinitions.getSourceSchema(getSourceType());

  LinkedBuffer buffer = LinkedBuffer.allocate(512);
  byte[] bytes = ProtobufIOUtil.toByteArray(this, schema, buffer);

  return ByteString.copyFrom(bytes);
}
 
开发者ID:dremio,项目名称:dremio-oss,代码行数:10,代码来源:Source.java

示例10: instantiateGlobalVar

import io.protostuff.ProtobufIOUtil; //导入方法依赖的package包/类
public boolean instantiateGlobalVar(Object key,String nickName, Object[] defaultVarValue,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 ########################

		JCL_message_global_var_obj gvMessage = new MessageGlobalVarObjImpl(nickName, byK, defaultVarValue);
		gvMessage.setType(9);

		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 (Boolean) result.getCorrectResult();

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

示例11: instantiateGlobalVar

import io.protostuff.ProtobufIOUtil; //导入方法依赖的package包/类
public boolean instantiateGlobalVar(Object key,String nickName, Object[] defaultVarValue,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 ########################

			JCL_message_global_var_obj gvMessage = new MessageGlobalVarObjImpl(nickName, byK, defaultVarValue);
			gvMessage.setType(9);
			
			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 (Boolean) result.getCorrectResult();

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

示例12: instantiateGlobalVarOnHost

import io.protostuff.ProtobufIOUtil; //导入方法依赖的package包/类
public Object instantiateGlobalVarOnHost(Map<String,String> hostP,
		Object key, String serverAdd,int serverPort) {
	try {
		JCL_message_generic mc = new MessageGenericImpl();

		String mac = hostP.get("MAC");
  		  String portS = hostP.get("PORT_SUPER_PEER");
  		  
		if (hostP.size() >= 4) {
			
			// register host on server
			// ################ Serialization key ########################
			LinkedBuffer buffer = LinkedBuffer.allocate(1048576);
			ObjectWrap objW = new ObjectWrap(key);					
			byte[] byK = ProtobufIOUtil.toByteArray(objW,scow, buffer);			
			// ################ Serialization key ########################

			Object[] obj = {byK, hostP};
			mc.setRegisterData(obj);
			mc.setType(21);
			JCL_connector controlConnector = new ConnectorImpl();
			controlConnector.connect(serverAdd, serverPort,mac);
			JCL_message_control mr = (JCL_message_control) controlConnector.sendReceiveG(mc,portS);
			controlConnector.disconnect();
			return new Boolean(mr.getRegisterData()[0]).booleanValue();
			
		} else{
			return null;
		}
	} catch (Exception e){
		System.err
				.println("problem in JCL facade instantiateGlobalVarOnHost(String host, String nickName, String varName, File[] jars, Object[] defaultVarValue)");
		return null;
	}
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:36,代码来源:JCL_FacadeImplLamb.java

示例13: instantiateGlobalVarOnHost

import io.protostuff.ProtobufIOUtil; //导入方法依赖的package包/类
public Object instantiateGlobalVarOnHost(Map<String,String> hostP,
										 Object key, String serverAdd,int serverPort) {
	try {
		JCL_message_generic mc = new MessageGenericImpl();

		String mac = hostP.get("MAC");
		String portS = hostP.get("PORT_SUPER_PEER");

		if (hostP.size() >= 4) {

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

			Object[] obj = {byK, hostP};
			mc.setRegisterData(obj);
			mc.setType(21);
			JCL_connector controlConnector = new ConnectorImpl();
			controlConnector.connect(serverAdd, serverPort,mac);
			JCL_message_control mr = (JCL_message_control) controlConnector.sendReceiveG(mc,portS);
			controlConnector.disconnect();
			return new Boolean(mr.getRegisterData()[0]).booleanValue();

		} else{
			return null;
		}
	} catch (Exception e){
		System.err
				.println("problem in JCL facade instantiateGlobalVarOnHost(String host, String nickName, String varName, File[] jars, Object[] defaultVarValue)");
		return null;
	}
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:36,代码来源:JCL_FacadeImplLamb.java

示例14: containsKey

import io.protostuff.ProtobufIOUtil; //导入方法依赖的package包/类
protected boolean containsKey(String gvName,Object Key, int IDhost){

			//Get Ip host
			Entry<String, Map<String, String>> hostPort = devicesStorage.get(IDhost);

			String host = hostPort.getValue().get("IP");
			String port = hostPort.getValue().get("PORT");
			String mac = hostPort.getValue().get("MAC");
			String portS = hostPort.getValue().get("PORT_SUPER_PEER");
			
			// ################ Serialization key ########################
			LinkedBuffer buffer = LinkedBuffer.allocate(1048576);
			ObjectWrap objW = new ObjectWrap(Key);	
			Schema scow = RuntimeSchema.getSchema(ObjectWrap.class);
			Key = ProtobufIOUtil.toByteArray(objW,scow, buffer);			
			// ################ Serialization key ########################


			//containsKey using lambari
			JCL_message_generic mc = new MessageGenericImpl();
			Object[] ob = {gvName,Key};
			mc.setRegisterData(ob);
			mc.setType(31);
			JCL_connector controlConnector = new ConnectorImpl();
			controlConnector.connect(host,Integer.parseInt(port),mac);
			JCL_message_generic mr = (JCL_message_generic) controlConnector.sendReceiveG(mc,portS);
			controlConnector.disconnect();
			return (Boolean) mr.getRegisterData();
		}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:30,代码来源:JCL_FacadeImpl.java

示例15: getValue

import io.protostuff.ProtobufIOUtil; //导入方法依赖的package包/类
public Object getValue(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(14);

		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 getValue");
		e.printStackTrace();
		return null;
	}
}
 
开发者ID:AndreJCL,项目名称:JCL,代码行数:29,代码来源:JCL_FacadeImplLamb.java


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