Java Code Examples for io.protostuff.ProtostuffIOUtil#parseListFrom()
The following examples show how to use
io.protostuff.ProtostuffIOUtil#parseListFrom() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImmutableObjectsTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testPojo() throws Exception { Schema<Pojo> schema = RuntimeSchema.getSchema(Pojo.class); Pojo p = new Pojo().fill(); byte[] data = ProtostuffIOUtil.toByteArray(p, schema, buf()); Pojo p2 = new Pojo(); ProtostuffIOUtil.mergeFrom(data, 0, data.length, p2, schema); assertEquals(p, p2); List<Pojo> list = new ArrayList<Pojo>(); list.add(p); list.add(p2); ByteArrayOutputStream out = new ByteArrayOutputStream(); ProtostuffIOUtil.writeListTo(out, list, schema, buf()); byte[] listData = out.toByteArray(); ByteArrayInputStream in = new ByteArrayInputStream(listData); List<Pojo> parsedList = ProtostuffIOUtil.parseListFrom(in, schema); assertEquals(list, parsedList); }
Example 2
Source File: PolymorphicSerializationTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testProtostuff() throws Exception { Schema<Zoo> schema = RuntimeSchema.getSchema(Zoo.class); Zoo p = filledZoo(); byte[] data = ProtostuffIOUtil.toByteArray(p, schema, buf()); // System.err.println("protostuff: " + data.length); Zoo p2 = new Zoo(); ProtostuffIOUtil.mergeFrom(data, 0, data.length, p2, schema); assertEquals(p, p2); List<Zoo> list = new ArrayList<Zoo>(); list.add(p); list.add(p2); ByteArrayOutputStream out = new ByteArrayOutputStream(); ProtostuffIOUtil.writeListTo(out, list, schema, buf()); byte[] listData = out.toByteArray(); ByteArrayInputStream in = new ByteArrayInputStream(listData); List<Zoo> parsedList = ProtostuffIOUtil.parseListFrom(in, schema); assertEquals(list, parsedList); }
Example 3
Source File: DateTest.java From protostuff with Apache License 2.0 | 6 votes |
public void testProtostuff() throws Exception { Schema<Entity> schema = RuntimeSchema.getSchema(Entity.class); Entity p = filledEntity(); byte[] data = ProtostuffIOUtil.toByteArray(p, schema, LinkedBuffer.allocate(512)); Entity p2 = new Entity(); ProtostuffIOUtil.mergeFrom(data, 0, data.length, p2, schema); assertEquals(p, p2); List<Entity> list = new ArrayList<Entity>(); list.add(p); list.add(p2); ByteArrayOutputStream out = new ByteArrayOutputStream(); ProtostuffIOUtil.writeListTo(out, list, schema, buf()); byte[] listData = out.toByteArray(); ByteArrayInputStream in = new ByteArrayInputStream(listData); List<Entity> parsedList = ProtostuffIOUtil.parseListFrom(in, schema); assertEquals(list, parsedList); }
Example 4
Source File: ProtoStuffSerializeUtil.java From ns4_frame with Apache License 2.0 | 5 votes |
@Deprecated public static <T> List<T> unSerializeForList(byte[] bs,Class<T> cl) throws IOException { ByteArrayInputStream arrayInputStream = new ByteArrayInputStream(bs); Schema<T> schema = RuntimeSchema.getSchema(cl); List<T> lst = ProtostuffIOUtil.parseListFrom(arrayInputStream,schema); arrayInputStream.close(); return lst; }
Example 5
Source File: ProtoStuffSerializeUtil.java From jim-framework with Apache License 2.0 | 5 votes |
public static <T> List<T> deserializeList(byte[] bytes, Class<T> targetClass) { if (bytes == null || bytes.length == 0) { return null; } Schema<T> schema = RuntimeSchema.getSchema(targetClass); try { return ProtostuffIOUtil.parseListFrom(new ByteArrayInputStream(bytes), schema); } catch (IOException e) { logger.info("ProtoStuffSerialize.deserializeList error:",e); } return null; }
Example 6
Source File: MathObjectsTest.java From protostuff with Apache License 2.0 | 5 votes |
public void testProtostuff() throws Exception { Schema<Payment> schema = RuntimeSchema.getSchema(Payment.class); Payment p = filledPayment(); byte[] data = ProtostuffIOUtil.toByteArray(p, schema, buf()); Payment p2 = new Payment(); ProtostuffIOUtil.mergeFrom(data, 0, data.length, p2, schema); /* * System.err.println(p2.getId()); System.err.println(p2.getBd()); System.err.println(p2.getBi()); * System.err.println(p2.getBdList()); System.err.println(p2.getBiList()); */ assertEquals(p, p2); List<Payment> list = new ArrayList<Payment>(); list.add(p); list.add(p2); ByteArrayOutputStream out = new ByteArrayOutputStream(); ProtostuffIOUtil.writeListTo(out, list, schema, buf()); byte[] listData = out.toByteArray(); ByteArrayInputStream in = new ByteArrayInputStream(listData); List<Payment> parsedList = ProtostuffIOUtil.parseListFrom(in, schema); assertEquals(list, parsedList); }
Example 7
Source File: ImmutableObjectsTest.java From protostuff with Apache License 2.0 | 5 votes |
public void testImmutablePojo() throws Exception { Schema<ImmutablePojo> schema = RuntimeSchema .getSchema(ImmutablePojo.class); ImmutablePojo p = new ImmutablePojo(3, "ip"); byte[] data = ProtostuffIOUtil.toByteArray(p, schema, buf()); ImmutablePojo p2 = schema.newMessage(); ProtostuffIOUtil.mergeFrom(data, 0, data.length, p2, schema); assertEquals(p, p2); List<ImmutablePojo> list = new ArrayList<ImmutablePojo>(); list.add(p); list.add(p2); ByteArrayOutputStream out = new ByteArrayOutputStream(); ProtostuffIOUtil.writeListTo(out, list, schema, buf()); byte[] listData = out.toByteArray(); ByteArrayInputStream in = new ByteArrayInputStream(listData); List<ImmutablePojo> parsedList = ProtostuffIOUtil.parseListFrom(in, schema); assertEquals(list, parsedList); }
Example 8
Source File: EnumSetAndMapTest.java From protostuff with Apache License 2.0 | 5 votes |
public void testPojoWithEnumSet() throws Exception { Schema<PojoWithEnumSet> schema = RuntimeSchema .getSchema(PojoWithEnumSet.class); PojoWithEnumSet p = new PojoWithEnumSet().fill(); byte[] data = ProtostuffIOUtil.toByteArray(p, schema, buf()); PojoWithEnumSet p2 = new PojoWithEnumSet(); ProtostuffIOUtil.mergeFrom(data, 0, data.length, p2, schema); assertEquals(p, p2); List<PojoWithEnumSet> list = new ArrayList<PojoWithEnumSet>(); list.add(p); list.add(p2); ByteArrayOutputStream out = new ByteArrayOutputStream(); ProtostuffIOUtil.writeListTo(out, list, schema, buf()); byte[] listData = out.toByteArray(); ByteArrayInputStream in = new ByteArrayInputStream(listData); List<PojoWithEnumSet> parsedList = ProtostuffIOUtil.parseListFrom(in, schema); assertEquals(list, parsedList); }
Example 9
Source File: EnumSetAndMapTest.java From protostuff with Apache License 2.0 | 5 votes |
public void testPojoWithEnumMap() throws Exception { Schema<PojoWithEnumMap> schema = RuntimeSchema .getSchema(PojoWithEnumMap.class); PojoWithEnumMap p = new PojoWithEnumMap().fill(); byte[] data = ProtostuffIOUtil.toByteArray(p, schema, buf()); PojoWithEnumMap p2 = new PojoWithEnumMap(); ProtostuffIOUtil.mergeFrom(data, 0, data.length, p2, schema); assertEquals(p, p2); List<PojoWithEnumMap> list = new ArrayList<PojoWithEnumMap>(); list.add(p); list.add(p2); ByteArrayOutputStream out = new ByteArrayOutputStream(); ProtostuffIOUtil.writeListTo(out, list, schema, buf()); byte[] listData = out.toByteArray(); ByteArrayInputStream in = new ByteArrayInputStream(listData); List<PojoWithEnumMap> parsedList = ProtostuffIOUtil.parseListFrom(in, schema); assertEquals(list, parsedList); }
Example 10
Source File: RecordCopier.java From DataLink with Apache License 2.0 | 4 votes |
public static <T> List<T> deserializeList(byte[] paramArrayOfByte, Class<T> targetClass) throws Exception { Schema<T> schema = RuntimeSchema.getSchema(targetClass); return ProtostuffIOUtil.parseListFrom(new ByteArrayInputStream(paramArrayOfByte), schema); }