Package com.alibaba.dubbo.common.io

Examples of com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream.toByteArray()


    UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
    Builder<TestDO> builder = Builder.register(TestDO.class);
    TestDO d = new TestDOImpl();
    builder.writeTo(d, os);

    byte[] b = os.toByteArray();

    d = builder.parseFrom(b);
    assertTrue(TestDO.class.isAssignableFrom(d.getClass()));
    assertEquals("name", d.getName());
    assertEquals(28, d.getArg());
View Full Code Here


    UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
    Builder<Object> ob = Builder.register(Object.class);

    Object o = new Object();
    ob.writeTo(o, os);
    byte[] b = os.toByteArray();

    os = new UnsafeByteArrayOutputStream();
    Bean bean = new Bean();
    bean.name = "ql";
    bean.type = Type.High;
View Full Code Here

    bean.name = "ql";
    bean.type = Type.High;
    bean.types = new Type[]{ Type.High, Type.High };
    ob.writeTo(bean, os);

    b = os.toByteArray();
    bean = (Bean)ob.parseFrom(b);
    assertEquals(bean.i, 123123);
    assertEquals(bean.ni, -12344);
    assertEquals(bean.d, 12.345);
    assertEquals(bean.nd, -12.345);
View Full Code Here

    obj[2] = "3455";
    obj[3] = null;
    obj[4] = Boolean.TRUE;

    builder.writeTo(obj, os);
    byte[] b = os.toByteArray();
    System.out.println("Object array:"+b.length+":"+Bytes.bytes2hex(b));

    Assert.assertArrayEquals(obj, builder.parseFrom(b));
  }
View Full Code Here

    list.add(4);
    list.code = 4321;
   
    UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
    b1.writeTo(list, os);
    byte[] b = os.toByteArray();
    System.out.println(b.length+":"+Bytes.bytes2hex(b));
    MyList result = b1.parseFrom(b);

    assertEquals(4, result.size());
    assertEquals(result.code, 4321);
View Full Code Here

        MyMap map = new MyMap();
        map.put("name", "qianlei");
        map.put("displayName", "钱磊");
        map.code = 4321;
        b2.writeTo(map, os);
        byte[] b = os.toByteArray();
        System.out.println(b.length+":"+Bytes.bytes2hex(b));
       
        map = b2.parseFrom(b);
       
        assertEquals(map.size(), 2);
View Full Code Here

    SerializableBean sb = new SerializableBean();
    Builder<SerializableBean> sbb = Builder.register(SerializableBean.class);
    sbb.writeTo(sb, os);

    byte[] b = os.toByteArray();
    System.out.println(b.length+":"+Bytes.bytes2hex(b));
    assertEquals(sbb.parseFrom(os.toByteArray()), sb);
  }

    @Test
View Full Code Here

    Builder<SerializableBean> sbb = Builder.register(SerializableBean.class);
    sbb.writeTo(sb, os);

    byte[] b = os.toByteArray();
    System.out.println(b.length+":"+Bytes.bytes2hex(b));
    assertEquals(sbb.parseFrom(os.toByteArray()), sb);
  }

    @Test
  @SuppressWarnings("unchecked")
  public void testOthers() throws Exception
View Full Code Here

    StringBuffer buf = new StringBuffer();
    for(int i=0;i<1024*32+32;i++)
      buf.append('A');
    Builder<String> sb = Builder.register(String.class);
    sb.writeTo(buf.toString(), os);
    assertEquals(sb.parseFrom(os.toByteArray()), buf.toString());

    os = new UnsafeByteArrayOutputStream();
    Builder<HashMap> builder = Builder.register(HashMap.class);
    Map services = new HashMap();
    HashMap map = new HashMap();
View Full Code Here

    map.put("name", "qianlei");
    map.put("password", "123455");
    map.put("services", services);

    builder.writeTo(map, os);
    byte[] b = os.toByteArray();
    System.out.println(b.length+":"+Bytes.bytes2hex(b));
    map = builder.parseFrom(b);
    assertTrue(map.size() > 0);
        assertEquals("http://127.0.0.1:9010/test.service", ((Map) map.get("services")).get("test.service"));
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.