当前位置: 首页>>代码示例>>Java>>正文


Java UnsafeByteArrayOutputStream类代码示例

本文整理汇总了Java中com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream的典型用法代码示例。如果您正苦于以下问题:Java UnsafeByteArrayOutputStream类的具体用法?Java UnsafeByteArrayOutputStream怎么用?Java UnsafeByteArrayOutputStream使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


UnsafeByteArrayOutputStream类属于com.alibaba.dubbo.common.io包,在下文中一共展示了UnsafeByteArrayOutputStream类的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeTo

import com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream; //导入依赖的package包/类
@Override
public void writeTo(Serializable obj, GenericObjectOutput out) throws IOException
{
	if( obj == null )
	{
		out.write0(OBJECT_NULL);
	}
	else
	{
		out.write0(OBJECT_STREAM);
		UnsafeByteArrayOutputStream bos = new UnsafeByteArrayOutputStream();
		CompactedObjectOutputStream oos = new CompactedObjectOutputStream(bos);
		oos.writeObject(obj);
		oos.flush();
		bos.close();
		byte[] b = bos.toByteArray();
		out.writeUInt(b.length);
		out.write0(b, 0, b.length);
	}
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:21,代码来源:Builder.java

示例2: testInterfaceBuilder

import com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream; //导入依赖的package包/类
@Test
public void testInterfaceBuilder() throws Exception
{
	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());
	assertEquals(Type.High, d.getType());
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:17,代码来源:BuilderTest.java

示例3: testObjectArrayBuilder

import com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream; //导入依赖的package包/类
@Test
public void testObjectArrayBuilder() throws Exception
{
	UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
	Builder<Object[]> builder = Builder.register(Object[].class);

	Object[] obj = new Object[5];
	obj[0] = "1234";
	obj[1] = new Double(109.23);
	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));
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:20,代码来源:BuilderTest.java

示例4: testBuilder_MyList

import com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream; //导入依赖的package包/类
@Ignore
   @Test
   @SuppressWarnings({ "rawtypes", "unchecked" })
   public void testBuilder_MyList() throws Exception
{
       Builder<MyList> b1 = Builder.register(MyList.class);
	MyList list = new MyList();
	list.add(new boolean[]{ true,false });
	list.add(new int[]{ 1,2,3,4,5 });
	list.add("String");
	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);
	assertEquals(result.id, "feedback");
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:24,代码来源:BuilderTest.java

示例5: testBuilder_MyMap

import com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream; //导入依赖的package包/类
@Test
@SuppressWarnings({ "rawtypes", "unchecked" })
public void testBuilder_MyMap() throws Exception
{
    UnsafeByteArrayOutputStream os = new UnsafeByteArrayOutputStream();
    Builder<MyMap> b2 = Builder.register(MyMap.class);
    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);
    assertEquals(map.code, 4321);
    assertEquals(map.id, "feedback");
}
 
开发者ID:dachengxi,项目名称:EatDubbo,代码行数:21,代码来源:BuilderTest.java


注:本文中的com.alibaba.dubbo.common.io.UnsafeByteArrayOutputStream类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。