當前位置: 首頁>>代碼示例>>Java>>正文


Java GraphIOUtil類代碼示例

本文整理匯總了Java中io.protostuff.GraphIOUtil的典型用法代碼示例。如果您正苦於以下問題:Java GraphIOUtil類的具體用法?Java GraphIOUtil怎麽用?Java GraphIOUtil使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


GraphIOUtil類屬於io.protostuff包,在下文中一共展示了GraphIOUtil類的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: copy

import io.protostuff.GraphIOUtil; //導入依賴的package包/類
/**
 * Clone  a Protostuff object
 *
 * @param t the protobuf message to copy
 * @return a deep copy of {@code t}
 */
public static <T extends Message<T>> T copy(T t) {
  try {
    Schema<T> schema = t.cachedSchema();
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    GraphIOUtil.writeDelimitedTo(new DataOutputStream(out), t, schema);
    // TODO: avoid array copy
    ByteArrayInputStream in = new ByteArrayInputStream(out.toByteArray());
    T newMessage = schema.newMessage();
    GraphIOUtil.mergeDelimitedFrom(in, newMessage, schema);
    return newMessage;
  } catch (IOException e) {
    throw UserException.dataReadError(e)
      .message("Failure decoding object, please ensure that you ran dremio-admin upgrade on Dremio.")
      .build(logger);
  }
}
 
開發者ID:dremio,項目名稱:dremio-oss,代碼行數:23,代碼來源:ProtostuffUtil.java

示例2: testGraph

import io.protostuff.GraphIOUtil; //導入依賴的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

示例3: testBeanCyclic

import io.protostuff.GraphIOUtil; //導入依賴的package包/類
public void testBeanCyclic()
{
    System.err.println(RuntimeEnv.COLLECTION_SCHEMA_ON_REPEATED_FIELDS);

    Bean bean = fillCyclic(new Bean());

    verifyCyclic(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);

    verifyCyclic(deBean);
}
 
開發者ID:protostuff,項目名稱:protostuff,代碼行數:19,代碼來源:EnumSetAndMapTest.java

示例4: translate

import io.protostuff.GraphIOUtil; //導入依賴的package包/類
@Override
@SuppressWarnings("unchecked")
public byte[] translate(RequestWrapper requestWrapper, ResponseWrapper responseWrapper) throws IOException {
  Object result = responseWrapper.getResult();
  Schema schema;
  try {
    schema = schemaCache.get(result.getClass());
  } catch (ExecutionException e) {
    schema = RuntimeSchema.getSchema(result.getClass());
  }
  return GraphIOUtil.toByteArray(result, schema, LinkedBuffer.allocate(LinkedBuffer.DEFAULT_BUFFER_SIZE));
}
 
開發者ID:orctom,項目名稱:laputa,代碼行數:13,代碼來源:ProtoBufContentTranslator.java

示例5: serializeGraph

import io.protostuff.GraphIOUtil; //導入依賴的package包/類
private static <T> byte[] serializeGraph(T object)
{
    @SuppressWarnings("unchecked")
    Class<T> clazz = (Class<T>) object.getClass();
    Schema<T> schema = RuntimeSchema.getSchema(clazz);
    return GraphIOUtil.toByteArray(object, schema, LinkedBuffer.allocate());
}
 
開發者ID:protostuff,項目名稱:protostuff,代碼行數:8,代碼來源:RuntimeGraphUnknownFieldTest.java

示例6: deserializeGraph

import io.protostuff.GraphIOUtil; //導入依賴的package包/類
private static <T> T deserializeGraph(byte[] bytes, Class<T> clz)
{
    Schema<T> schema = RuntimeSchema.getSchema(clz);
    T obj = schema.newMessage();
    GraphIOUtil.mergeFrom(bytes, obj, schema);
    return obj;
}
 
開發者ID:protostuff,項目名稱:protostuff,代碼行數:8,代碼來源:RuntimeGraphUnknownFieldTest.java

示例7: testIt

import io.protostuff.GraphIOUtil; //導入依賴的package包/類
public void testIt() throws IOException
{
    RuntimeSchema.register(MainData.class);
    
    MainData testdata = new MainData("test", 123);
    ObjPackage obj = new ObjPackage();
    obj.setObj(testdata);
    testdata.put("aaaa", "bbb");
    Schema<ObjPackage> schema = RuntimeSchema.getSchema(ObjPackage.class);
    LinkedBuffer buffer = LinkedBuffer.allocate(256);
    ByteArrayOutputStream oss = new ByteArrayOutputStream(1024);
    
    GraphIOUtil.writeTo(oss, obj, schema, buffer);
    
    ObjPackage objParsed = schema.newMessage();
    GraphIOUtil.mergeFrom(oss.toByteArray(), objParsed, schema);
    
    assertTrue(objParsed.obj instanceof MainData);
    verifyEquals(testdata, (MainData)objParsed.obj);
    
    assertTrue(objParsed.data != null);
    verifyEquals(testdata, objParsed.data);
    
    assertTrue(objParsed.olist != null && 
            objParsed.olist.size() == 1 &&
            objParsed.olist.get(0) instanceof MainData);
    verifyEquals(testdata, (MainData)objParsed.olist.get(0));
    
    assertTrue(objParsed.list != null && 
            objParsed.list.size() == 1);
    verifyEquals(testdata, (MainData)objParsed.list.get(0));
    
    assertTrue(objParsed.omap != null && 
            objParsed.omap.size() == 1 &&
            objParsed.omap.get("obj") instanceof MainData);
    verifyEquals(testdata, (MainData)objParsed.omap.get("obj"));
    
    assertTrue(objParsed.map != null && 
            objParsed.map.size() == 1 &&
            objParsed.map.get("obj") instanceof MainData);
    verifyEquals(testdata, (MainData)objParsed.map.get("obj"));
}
 
開發者ID:protostuff,項目名稱:protostuff,代碼行數:43,代碼來源:LazyRegisterTest.java


注:本文中的io.protostuff.GraphIOUtil類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。