Java Code Examples for com.caucho.hessian.io.Hessian2Input#setSerializerFactory()
The following examples show how to use
com.caucho.hessian.io.Hessian2Input#setSerializerFactory() .
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: SpecialClassTest.java From sofa-hessian with Apache License 2.0 | 6 votes |
/** * 这个用例说明hessian写入的Iterator,反序列化时是ArrayList, 不兼容 * @throws Exception */ @Test public void testIterator() throws Exception { List<Integer> list = new ArrayList<Integer>(); list.add(1); list.add(2); Iterator<Integer> iterable = list.iterator(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new SerializerFactory()); hout.writeObject(iterable); hout.close(); byte[] body = bout.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length); Hessian2Input hin = new Hessian2Input(bin); hin.setSerializerFactory(new SerializerFactory()); Object o = hin.readObject(); assertEquals(ArrayList.class, o.getClass()); }
Example 2
Source File: SimpleTestGO2O.java From sofa-hessian with Apache License 2.0 | 6 votes |
@org.junit.Test public void testNull() throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new GenericSerializerFactory()); hout.writeObject(dg.generateNull()); hout.close(); byte[] body = bout.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length); Hessian2Input hin = new Hessian2Input(bin); hin.setSerializerFactory(new SerializerFactory()); assertNull(hin.readObject()); hin.close(); }
Example 3
Source File: SimpleTestGO2O.java From sofa-hessian with Apache License 2.0 | 6 votes |
@org.junit.Test public void testDate() throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new GenericSerializerFactory()); hout.writeObject(dg.generateDate_0()); hout.writeObject(dg.generateDate_1()); hout.writeObject(dg.generateDate_2()); hout.close(); byte[] body = bout.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length); Hessian2Input hin = new Hessian2Input(bin); hin.setSerializerFactory(new SerializerFactory()); assertEquals(dg.generateDate_0(), hin.readObject()); assertEquals(dg.generateDate_1(), hin.readObject()); assertEquals(dg.generateDate_2(), hin.readObject()); hin.close(); }
Example 4
Source File: SofaHessianSerializer.java From sofa-rpc with Apache License 2.0 | 6 votes |
@Override public Object decode(AbstractByteBuf data, Class clazz, Map<String, String> context) throws SofaRpcException { if (clazz == null) { throw buildDeserializeError("class is null!"); } else { CustomHessianSerializer serializer = CustomHessianSerializerManager.getSerializer(clazz); if (serializer != null) { return serializer.decodeObject(data, context); } else { try { UnsafeByteArrayInputStream inputStream = new UnsafeByteArrayInputStream(data.array()); Hessian2Input input = new Hessian2Input(inputStream); input.setSerializerFactory(serializerFactory); Object object = input.readObject(); input.close(); return object; } catch (IOException e) { throw buildDeserializeError(e.getMessage(), e); } } } }
Example 5
Source File: Hessian2BlackListTest.java From sofa-hessian with Apache License 2.0 | 6 votes |
@Test public void testMapDeserialize() throws IOException { byte[] bs = new byte[] { 77, 79, -81, 99, 111, 109, 46, 97, 108, 105, 112, 97, 121, 46, 115, 116, 99, 46, 98, 108, 46, 84, 101, 115, 116, 66, 108, 97, 99, 107, 66, 101, 97, 110, -111, 6, 115, 116, 114, 105, 110, 103, 111, -112, 3, 115, 115, 115, 74, 1, 122 }; ByteArrayInputStream input = new ByteArrayInputStream(bs, 0, bs.length); Hessian2Input hin = new Hessian2Input(input); hin.setSerializerFactory(serializerFactory); try { hin.readObject(); Assert.fail(); } catch (Exception e) { Assert.assertTrue(e instanceof IOException); } }
Example 6
Source File: Hessian2BlackListTest.java From sofa-hessian with Apache License 2.0 | 6 votes |
@Test public void testListDeserialize() throws IOException { byte[] bs = new byte[] { 86, 110, 1, 79, -81, 99, 111, 109, 46, 97, 108, 105, 112, 97, 121, 46, 115, 116, 99, 46, 98, 108, 46, 84, 101, 115, 116, 66, 108, 97, 99, 107, 66, 101, 97, 110, -111, 6, 115, 116, 114, 105, 110, 103, 111, -112, 3, 115, 115, 115, 122 }; ByteArrayInputStream input = new ByteArrayInputStream(bs, 0, bs.length); Hessian2Input hin = new Hessian2Input(input); hin.setSerializerFactory(serializerFactory); try { hin.readObject(); Assert.fail(); } catch (Exception e) { Assert.assertTrue(e instanceof IOException); } }
Example 7
Source File: SimpleTestO2GO.java From sofa-hessian with Apache License 2.0 | 6 votes |
@org.junit.Test public void testNull() throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new SerializerFactory()); hout.writeObject(dg.generateNull()); hout.close(); byte[] body = bout.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length); Hessian2Input hin = new Hessian2Input(bin); hin.setSerializerFactory(new GenericSerializerFactory()); assertNull(hin.readObject()); hin.close(); }
Example 8
Source File: CollectionTest.java From sofa-hessian with Apache License 2.0 | 5 votes |
@Test public void test2ObjectArray() throws Exception { Object[][] strs = new Object[2][3]; strs[0][0] = "11111"; strs[1][1] = "22222"; ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new GenericSerializerFactory()); hout.writeObject(strs); hout.close(); byte[] body = bout.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length); Hessian2Input hin = new Hessian2Input(bin); hin.setSerializerFactory(new GenericSerializerFactory()); Object o = hin.readObject(); assertTrue(o.getClass() == GenericArray.class); GenericArray ga1 = (GenericArray) o; assertEquals(Object[].class.getName(), ga1.getComponentType()); assertEquals(2, ga1.getLength()); GenericArray ga2 = (GenericArray) ga1.getObjects()[0]; assertEquals(3, ga2.getLength()); assertEquals("11111", ga2.getObjects()[0]); }
Example 9
Source File: ComplexTestO2GO.java From sofa-hessian with Apache License 2.0 | 5 votes |
@Test public void testList() throws IOException { List list = (List) dg.generateListPerson_1(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new SerializerFactory()); hout.writeObject(list); hout.close(); byte[] body = bout.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length); Hessian2Input hin = new Hessian2Input(bin); hin.setSerializerFactory(new GenericSerializerFactory()); List dlist = (List) hin.readObject(); assertEquals(dlist.size(), list.size()); ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) dlist.get(0), (Person) list.get(0)); ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) dlist.get(1), (Person) list.get(1)); List dlist2 = (List) dlist.get(2); List list2 = (List) list.get(2); assertEquals(dlist2.size(), list2.size()); ComplexTestGO2GO .cmpGPersonEqualPerson((GenericObject) dlist2.get(0), (Person) list2.get(0)); ComplexTestGO2GO .cmpGPersonEqualPerson((GenericObject) dlist2.get(1), (Person) list2.get(1)); ComplexTestGO2GO .cmpGPersonEqualPerson((GenericObject) dlist2.get(2), (Person) list2.get(2)); assertSame(dlist2.get(0), dlist2.get(2)); }
Example 10
Source File: SofaResponseHessianSerializer.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Override public SofaResponse decodeObject(AbstractByteBuf data, Map<String, String> context) throws SofaRpcException { try { UnsafeByteArrayInputStream inputStream = new UnsafeByteArrayInputStream(data.array()); Hessian2Input input = new Hessian2Input(inputStream); // 根据SerializeType信息决定序列化器 Object object; boolean genericSerialize = context != null && isGenericResponse( context.get(RemotingConstants.HEAD_GENERIC_TYPE)); if (genericSerialize) { input.setSerializerFactory(genericSerializerFactory); GenericObject genericObject = (GenericObject) input.readObject(); SofaResponse sofaResponse = new SofaResponse(); sofaResponse.setErrorMsg((String) genericObject.getField("errorMsg")); sofaResponse.setAppResponse(genericObject.getField("appResponse")); sofaResponse.setResponseProps((Map<String, String>) genericObject.getField("responseProps")); object = sofaResponse; } else { input.setSerializerFactory(serializerFactory); object = input.readObject(); } input.close(); return (SofaResponse) object; } catch (IOException e) { throw buildDeserializeError(e.getMessage(), e); } }
Example 11
Source File: CollectionTest.java From sofa-hessian with Apache License 2.0 | 5 votes |
@Test public void testGenericCollection() throws Exception { TestList testList = new TestList(); testList.add(1); testList.add(new SimplePerson("wang", "coder")); GenericCollection collection = new GenericCollection(TestList.class.getName()); collection.setCollection(testList); ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new GenericSerializerFactory()); hout.writeObject(collection); hout.close(); byte[] body = bout.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length); Hessian2Input hin = new Hessian2Input(bin); hin.setSerializerFactory(new GenericSerializerFactory()); Object o = hin.readObject(); assertTrue(o.getClass() == GenericCollection.class); GenericCollection genericCollection = (GenericCollection) o; assertEquals(genericCollection.getType(), TestList.class.getName()); assertEquals(genericCollection.getCollection().size(), 2); assertEquals(((ArrayList) genericCollection.getCollection()).get(0), 1); assertEquals(((ArrayList) genericCollection.getCollection()).get(1).getClass(), GenericObject.class); GenericObject genericObject = (GenericObject) ((ArrayList) genericCollection .getCollection()).get(1); assertEquals(genericObject.getType(), SimplePerson.class.getName()); assertEquals(genericObject.getField("name"), "wang"); assertEquals(genericObject.getField("job"), "coder"); }
Example 12
Source File: SofaResponseHessianSerializer.java From sofa-rpc with Apache License 2.0 | 5 votes |
@Override public void decodeObjectByTemplate(AbstractByteBuf data, Map<String, String> context, SofaResponse template) throws SofaRpcException { try { UnsafeByteArrayInputStream inputStream = new UnsafeByteArrayInputStream(data.array()); Hessian2Input input = new Hessian2Input(inputStream); // 根据SerializeType信息决定序列化器 boolean genericSerialize = context != null && isGenericResponse( context.get(RemotingConstants.HEAD_GENERIC_TYPE)); if (genericSerialize) { input.setSerializerFactory(genericSerializerFactory); GenericObject genericObject = (GenericObject) input.readObject(); template.setErrorMsg((String) genericObject.getField("errorMsg")); template.setAppResponse(genericObject.getField("appResponse")); template.setResponseProps((Map<String, String>) genericObject.getField("responseProps")); } else { input.setSerializerFactory(serializerFactory); SofaResponse tmp = (SofaResponse) input.readObject(); // copy values to template template.setErrorMsg(tmp.getErrorMsg()); template.setAppResponse(tmp.getAppResponse()); template.setResponseProps(tmp.getResponseProps()); } input.close(); } catch (IOException e) { throw buildDeserializeError(e.getMessage(), e); } }
Example 13
Source File: SimpleTestO2GO.java From sofa-hessian with Apache License 2.0 | 5 votes |
@org.junit.Test public void testBinary() throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new SerializerFactory()); hout.writeObject(dg.generateBinary_0()); hout.writeObject(dg.generateBinary_null()); hout.writeObject(dg.generateBinary_1()); hout.writeObject(dg.generateBinary_15()); hout.writeObject(dg.generateBinary_16()); hout.writeObject(dg.generateBinary_1023()); hout.writeObject(dg.generateBinary_1024()); hout.writeObject(dg.generateBinary_65536()); hout.close(); byte[] body = bout.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length); Hessian2Input hin = new Hessian2Input(bin); hin.setSerializerFactory(new GenericSerializerFactory()); assertTrue(compareByteArray(dg.generateBinary_0(), hin.readObject())); assertNull(hin.readObject()); assertTrue(compareByteArray(dg.generateBinary_1(), hin.readObject())); assertTrue(compareByteArray(dg.generateBinary_15(), hin.readObject())); assertTrue(compareByteArray(dg.generateBinary_16(), hin.readObject())); assertTrue(compareByteArray(dg.generateBinary_1023(), hin.readObject())); assertTrue(compareByteArray(dg.generateBinary_1024(), hin.readObject())); assertTrue(compareByteArray(dg.generateBinary_65536(), hin.readObject())); hin.close(); }
Example 14
Source File: SimpleTestO2GO.java From sofa-hessian with Apache License 2.0 | 4 votes |
@org.junit.Test public void testDoubles() throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new SerializerFactory()); hout.writeObject(dg.generateDouble_0_0()); hout.writeObject(dg.generateDouble_1_0()); hout.writeObject(dg.generateDouble_2_0()); hout.writeObject(dg.generateDouble_127_0()); hout.writeObject(dg.generateDouble_m128_0()); hout.writeObject(dg.generateDouble_128_0()); hout.writeObject(dg.generateDouble_m129_0()); hout.writeObject(dg.generateDouble_32767_0()); hout.writeObject(dg.generateDouble_m32768_0()); hout.writeObject(dg.generateDouble_0_001()); hout.writeObject(dg.generateDouble_m0_001()); hout.writeObject(dg.generateDouble_65_536()); hout.writeObject(dg.generateDouble_3_14159()); hout.close(); byte[] body = bout.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length); Hessian2Input hin = new Hessian2Input(bin); hin.setSerializerFactory(new GenericSerializerFactory()); assertEquals(dg.generateDouble_0_0(), hin.readObject()); assertEquals(dg.generateDouble_1_0(), hin.readObject()); assertEquals(dg.generateDouble_2_0(), hin.readObject()); assertEquals(dg.generateDouble_127_0(), hin.readObject()); assertEquals(dg.generateDouble_m128_0(), hin.readObject()); assertEquals(dg.generateDouble_128_0(), hin.readObject()); assertEquals(dg.generateDouble_m129_0(), hin.readObject()); assertEquals(dg.generateDouble_32767_0(), hin.readObject()); assertEquals(dg.generateDouble_m32768_0(), hin.readObject()); assertEquals(dg.generateDouble_0_001(), hin.readObject()); assertEquals(dg.generateDouble_m0_001(), hin.readObject()); assertEquals(dg.generateDouble_65_536(), hin.readObject()); assertEquals(dg.generateDouble_3_14159(), hin.readObject()); hin.close(); }
Example 15
Source File: SimpleTesGO2GO.java From sofa-hessian with Apache License 2.0 | 4 votes |
@org.junit.Test public void testLong() throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new GenericSerializerFactory()); //single byte hout.writeObject(dg.generateLong_0()); hout.writeObject(dg.generateLong_1()); hout.writeObject(dg.generateLong_15()); hout.writeObject(dg.generateLong_m8()); //two bytes hout.writeObject(dg.generateLong_0x10()); hout.writeObject(dg.generateLong_0x7ff()); hout.writeObject(dg.generateLong_m9()); hout.writeObject(dg.generateLong_m0x800()); //three bytes hout.writeObject(dg.generateLong_0x800()); hout.writeObject(dg.generateLong_0x3ffff()); hout.writeObject(dg.generateLong_m0x801()); hout.writeObject(dg.generateLong_m0x40000()); //five bytes hout.writeObject(dg.generateLong_0x40000()); hout.writeObject(dg.generateLong_0x7fffffff()); hout.writeObject(dg.generateLong_m0x40001()); hout.writeObject(dg.generateLong_m0x80000000()); hout.writeObject(dg.generateLong_0x80000000()); hout.writeObject(dg.generateLong_m0x80000001()); hout.close(); byte[] body = bout.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length); Hessian2Input hin = new Hessian2Input(bin); hin.setSerializerFactory(new GenericSerializerFactory()); //single byte assertEquals(dg.generateLong_0(), hin.readObject()); assertEquals(dg.generateLong_1(), hin.readObject()); assertEquals(dg.generateLong_15(), hin.readObject()); assertEquals(dg.generateLong_m8(), hin.readObject()); //two bytes assertEquals(dg.generateLong_0x10(), hin.readObject()); assertEquals(dg.generateLong_0x7ff(), hin.readObject()); assertEquals(dg.generateLong_m9(), hin.readObject()); assertEquals(dg.generateLong_m0x800(), hin.readObject()); //three bytes assertEquals(dg.generateLong_0x800(), hin.readObject()); assertEquals(dg.generateLong_0x3ffff(), hin.readObject()); assertEquals(dg.generateLong_m0x801(), hin.readObject()); assertEquals(dg.generateLong_m0x40000(), hin.readObject()); //five bytes assertEquals(dg.generateLong_0x40000(), hin.readObject()); assertEquals(dg.generateLong_0x7fffffff(), hin.readObject()); assertEquals(dg.generateLong_m0x40001(), hin.readObject()); assertEquals(dg.generateLong_m0x80000000(), hin.readObject()); assertEquals(dg.generateLong_0x80000000(), hin.readObject()); assertEquals(dg.generateLong_m0x80000001(), hin.readObject()); hin.close(); }
Example 16
Source File: ComplexTestMix.java From sofa-hessian with Apache License 2.0 | 4 votes |
@Test public void testSofaRequest() throws IOException { SofaRequest request = dg.generateSofaRequest(); // serialization uses GenericHessian ByteArrayOutputStream byteArray = new ByteArrayOutputStream(); Hessian2Output output = new Hessian2Output(byteArray); output.setSerializerFactory(new GenericSerializerFactory()); output.writeObject(request); final Object[] args = request.getMethodArgs(); if (args != null) { for (int i = 0; i < args.length; i++) { output.writeObject(args[i]); } } output.close(); byteArray.close(); // deserialization uses Hessian byte[] body = byteArray.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length); Hessian2Input hin = new Hessian2Input(bin); hin.setSerializerFactory(new SerializerFactory()); SofaRequest deRequest = (SofaRequest) hin.readObject(); String[] sig = deRequest.getMethodArgSigs(); Class<?>[] classSig = new Class[sig.length]; final Object[] deArgs = new Object[sig.length]; for (int i = 0; i < deRequest.getMethodArgSigs().length; ++i) { deArgs[i] = hin.readObject(classSig[i]); } deRequest.setMethodArgs(deArgs); bin.close(); hin.close(); assertEquals(request.getTargetServiceUniqueName(), deRequest.getTargetServiceUniqueName()); assertEquals(request.getMethodName(), deRequest.getMethodName()); assertEquals(request.getTargetAppName(), deRequest.getTargetAppName()); assertEquals(request.getRequestProps(), deRequest.getRequestProps()); // 1st argument is a Person, and 2nd argument is an int cmpGPersonEqualPerson((GenericObject) request.getMethodArgs()[0], (Person) deRequest.getMethodArgs()[0]); assertEquals(request.getMethodArgs()[1], deRequest.getMethodArgs()[1]); }
Example 17
Source File: PersonTest.java From sofa-hessian with Apache License 2.0 | 4 votes |
public void testDiffDefinition() throws Exception { GenericObject go1 = new GenericObject(Person.class.getName()); go1.putField("name", "zhangsan"); // go1.putField("age", 12); go1.putField("gender", null); go1.putField("scores", new HashMap<String, Integer>()); go1.putField("friend", null); go1.putField("pet", GenericUtils.convertToGenericObject(new Pet())); // go1.putField("mapValue", null); go1.putField("listValue", new ArrayList<Object>()); GenericObject go2 = new GenericObject(Person.class.getName()); go2.putField("name", "lisi"); go2.putField("age", 21); // go2.putField("gender", "Femal"); go2.putField("scores", new HashMap<String, Integer>()); go2.putField("friend", GenericUtils.convertToGenericObject(new Person())); // go2.putField("pet", null); go2.putField("mapValue", null); go2.putField("listValue", null); ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new GenericSerializerFactory()); hout.writeObject(go1); hout.writeObject(go2); hout.close(); byte[] body = bout.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length); Hessian2Input hin = new Hessian2Input(bin); hin.setSerializerFactory(new SerializerFactory()); Person p1 = (Person) hin.readObject(); assertEquals("zhangsan", p1.getName()); // assertEquals(12, p1.getAge()); assertEquals(null, p1.getGender()); assertEquals(0, p1.getScores().size()); assertEquals(null, p1.getFriend()); assertNotNull(p1.getPet()); // assertEquals(null, p1.getMapValue()); assertEquals(0, p1.getListValue().size()); Person p2 = (Person) hin.readObject(); assertEquals("lisi", p2.getName()); assertEquals(21, p2.getAge()); // assertEquals("Femal", p2.getGender()); assertEquals(0, p2.getScores().size()); assertNotNull(p2.getFriend()); // assertEquals(null, p2.getPet()); assertEquals(null, p2.getMapValue()); assertEquals(null, p2.getListValue()); }
Example 18
Source File: Hessian2ObjectInput.java From JobX with Apache License 2.0 | 4 votes |
public Hessian2ObjectInput(InputStream is) { hessian2Input = new Hessian2Input(is); hessian2Input.setSerializerFactory(Hessian2SerializerFactory.SERIALIZER_FACTORY); }
Example 19
Source File: SimpleTestGO2O.java From sofa-hessian with Apache License 2.0 | 4 votes |
@org.junit.Test public void testLong() throws IOException { ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new GenericSerializerFactory()); //single byte hout.writeObject(dg.generateLong_0()); hout.writeObject(dg.generateLong_1()); hout.writeObject(dg.generateLong_15()); hout.writeObject(dg.generateLong_m8()); //two bytes hout.writeObject(dg.generateLong_0x10()); hout.writeObject(dg.generateLong_0x7ff()); hout.writeObject(dg.generateLong_m9()); hout.writeObject(dg.generateLong_m0x800()); //three bytes hout.writeObject(dg.generateLong_0x800()); hout.writeObject(dg.generateLong_0x3ffff()); hout.writeObject(dg.generateLong_m0x801()); hout.writeObject(dg.generateLong_m0x40000()); //five bytes hout.writeObject(dg.generateLong_0x40000()); hout.writeObject(dg.generateLong_0x7fffffff()); hout.writeObject(dg.generateLong_m0x40001()); hout.writeObject(dg.generateLong_m0x80000000()); hout.writeObject(dg.generateLong_0x80000000()); hout.writeObject(dg.generateLong_m0x80000001()); hout.close(); byte[] body = bout.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length); Hessian2Input hin = new Hessian2Input(bin); hin.setSerializerFactory(new SerializerFactory()); //single byte assertEquals(dg.generateLong_0(), hin.readObject()); assertEquals(dg.generateLong_1(), hin.readObject()); assertEquals(dg.generateLong_15(), hin.readObject()); assertEquals(dg.generateLong_m8(), hin.readObject()); //two bytes assertEquals(dg.generateLong_0x10(), hin.readObject()); assertEquals(dg.generateLong_0x7ff(), hin.readObject()); assertEquals(dg.generateLong_m9(), hin.readObject()); assertEquals(dg.generateLong_m0x800(), hin.readObject()); //three bytes assertEquals(dg.generateLong_0x800(), hin.readObject()); assertEquals(dg.generateLong_0x3ffff(), hin.readObject()); assertEquals(dg.generateLong_m0x801(), hin.readObject()); assertEquals(dg.generateLong_m0x40000(), hin.readObject()); //five bytes assertEquals(dg.generateLong_0x40000(), hin.readObject()); assertEquals(dg.generateLong_0x7fffffff(), hin.readObject()); assertEquals(dg.generateLong_m0x40001(), hin.readObject()); assertEquals(dg.generateLong_m0x80000000(), hin.readObject()); assertEquals(dg.generateLong_0x80000000(), hin.readObject()); assertEquals(dg.generateLong_m0x80000001(), hin.readObject()); hin.close(); }
Example 20
Source File: ComplexTestO2GO.java From sofa-hessian with Apache License 2.0 | 4 votes |
public void testMix() throws IOException { Object obj = dg.generateMixObject(); ByteArrayOutputStream bout = new ByteArrayOutputStream(); Hessian2Output hout = new Hessian2Output(bout); hout.setSerializerFactory(new SerializerFactory()); hout.writeObject(obj); hout.close(); byte[] body = bout.toByteArray(); ByteArrayInputStream bin = new ByteArrayInputStream(body, 0, body.length); Hessian2Input hin = new Hessian2Input(bin); hin.setSerializerFactory(new GenericSerializerFactory()); Object[][] darr = (Object[][]) hin.readObject(); Object[][] arr = (Object[][]) obj; assertEquals(darr.length, 3); assertEquals(darr[0].length, 3); assertSame(darr, darr[2][0]); ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) darr[2][1], (Person) arr[2][1]); ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) darr[2][2], (Person) arr[2][2]); Object[] darr1 = (Object[]) darr[1][0]; Map dmap1 = (Map) darr[1][1]; List dlist1 = (List) darr[1][2]; Object[] darr2 = (Object[]) darr1[2]; assertSame(darr2[2], dmap1); Map dmap2 = (Map) dmap1.get(3); assertSame(dmap2.get("www"), dlist1); List dlist2 = (List) dlist1.get(2); assertSame(dlist2.get(2), darr1); ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) darr1[0], (Person) ((Object[]) arr[1][0])[0]); assertSame(darr1[0], darr2[0]); assertSame(darr1[0], dmap1.get(1)); assertSame(darr1[0], dmap2.get("lll")); assertSame(darr1[0], dlist1.get(0)); assertSame(darr1[0], dlist2.get(0)); ComplexTestGO2GO.cmpGPersonEqualPerson((GenericObject) darr1[1], (Person) ((Object[]) arr[1][0])[1]); assertSame(darr1[1], darr2[1]); assertSame(darr1[1], dmap1.get(2)); assertSame(darr1[1], dmap2.get("qqq")); assertSame(darr1[1], dlist1.get(1)); assertSame(darr1[1], dlist2.get(1)); //System.out.println(darr1[1]); }