本文整理匯總了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);
}
}
示例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);
}
示例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);
}
示例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));
}
示例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());
}
示例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;
}
示例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"));
}