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


Java Serializer类代码示例

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


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

示例1: TestManyFloats

import net.razorvine.serpent.Serializer; //导入依赖的package包/类
@Test
	@Ignore
	public void TestManyFloats() throws IOException
	{
//		System.out.println("enter to start manyfloats");
//		System.in.read();
		
		int amount = 500000;
		double[] array = new double[amount];
		for(int i=0; i<amount; ++i)
			array[i] = 12345.987654;
		
		Serializer serpent = new Serializer();
		Parser parser = new Parser();
		long start = System.currentTimeMillis();
		byte[] data = serpent.serialize(array);
		long duration = System.currentTimeMillis()-start;
		System.out.println(""+duration+"  datalen="+data.length);
		start = System.currentTimeMillis();
		Object[] values = (Object[]) parser.parse(data).getData(); 
		duration = System.currentTimeMillis()-start;
		System.out.println(""+duration+"  valuelen="+values.length);
	}
 
开发者ID:irmen,项目名称:Serpent,代码行数:24,代码来源:SlowPerformanceTest.java

示例2: TestManyInts

import net.razorvine.serpent.Serializer; //导入依赖的package包/类
@Test
	@Ignore
	public void TestManyInts() throws IOException
	{
//		System.out.println("enter to start manyints");
//		System.in.read();

		int amount=500000;
		int[] array = new int[amount];
		for(int i=0; i<amount; ++i)
			array[i] = 12345;
		
		Serializer serpent = new Serializer();
		Parser parser = new Parser();
		long start = System.currentTimeMillis();
		byte[] data = serpent.serialize(array);
		long duration = System.currentTimeMillis()-start;
		System.out.println(""+duration+"  datalen="+data.length);
		start = System.currentTimeMillis();
		Object[] values = (Object[]) parser.parse(data).getData(); 
		duration = System.currentTimeMillis()-start;
		System.out.println(""+duration+"  valuelen="+values.length);
	}
 
开发者ID:irmen,项目名称:Serpent,代码行数:24,代码来源:SlowPerformanceTest.java

示例3: testHeader

import net.razorvine.serpent.Serializer; //导入依赖的package包/类
@Test
public void testHeader()
{
	Serializer ser = new Serializer();
	byte[] data = ser.serialize(null);
	assertEquals(35, data[0]);
	String strdata = S(data);
	assertEquals("# serpent utf-8 python3.2", strdata.split("\n")[0]);
	
	ser.setliterals=false;
	data = ser.serialize(null);
	strdata = S(data);
	assertEquals("# serpent utf-8 python2.6", strdata.split("\n")[0]);

	data = B("# header\nfirst-line");
	data = strip_header(data);
	assertEquals("first-line", S(data));
}
 
开发者ID:irmen,项目名称:Serpent,代码行数:19,代码来源:SerializeTest.java

示例4: testStuff

import net.razorvine.serpent.Serializer; //导入依赖的package包/类
@Test
public void testStuff()
{
	Serializer ser=new Serializer();
	byte[] result = ser.serialize("blerp");
	result=strip_header(result);
	assertEquals("'blerp'", S(result));
	result = ser.serialize("\\");
	result=strip_header(result);
	assertEquals("'\\\\'", S(result));
	result = ser.serialize(UUID.fromString("f1f8d00e-49a5-4662-ac1d-d5f0426ed293"));
	result=strip_header(result);
	assertEquals("'f1f8d00e-49a5-4662-ac1d-d5f0426ed293'", S(result));
	result = ser.serialize(new BigDecimal("123456789.987654321987654321987654321987654321"));
	result=strip_header(result);
	assertEquals("'123456789.987654321987654321987654321987654321'", S(result));
}
 
开发者ID:irmen,项目名称:Serpent,代码行数:18,代码来源:SerializeTest.java

示例5: testDateTime

import net.razorvine.serpent.Serializer; //导入依赖的package包/类
@Test
public void testDateTime()
{
	Serializer serpent = new Serializer();
	Calendar cal = new GregorianCalendar(2013, 0, 20, 23, 59, 45);
	cal.set(Calendar.MILLISECOND, 999);
	cal.setTimeZone(TimeZone.getTimeZone("GMT+0"));
	
	byte[] ser = strip_header(serpent.serialize(cal));
	assertEquals("'2013-01-20T23:59:45.999Z'", S(ser));

	Date date = cal.getTime();
	ser = strip_header(serpent.serialize(date));
	assertEquals("'2013-01-20T23:59:45.999Z'", S(ser));
	
	ser = strip_header(serpent.serialize(date));
	assertEquals("'2013-01-20T23:59:45.999Z'", S(ser));
	
	cal.set(Calendar.MILLISECOND, 0);
	ser = strip_header(serpent.serialize(cal));
	assertEquals("'2013-01-20T23:59:45Z'", S(ser));

	date = cal.getTime();
	ser = strip_header(serpent.serialize(date));
	assertEquals("'2013-01-20T23:59:45Z'", S(ser));
}
 
开发者ID:irmen,项目名称:Serpent,代码行数:27,代码来源:SerializeTest.java

示例6: testList

import net.razorvine.serpent.Serializer; //导入依赖的package包/类
@Test
public void testList()
{
	Serializer serpent = new Serializer();
	List<Object> list = new LinkedList<Object>();
	
	// test empty list
	byte[] ser = strip_header(serpent.serialize(list));
	assertEquals("[]", S(ser));
	serpent.indent=true;
	ser = strip_header(serpent.serialize(list));
	assertEquals("[]", S(ser));
	serpent.indent=false;
	
	// test nonempty list
	list.add(42);
	list.add("Sally");
	list.add(16.5);
	ser = strip_header(serpent.serialize(list));
	assertEquals("[42,'Sally',16.5]", S(ser));
	serpent.indent=true;
	ser = strip_header(serpent.serialize(list));
	assertEquals("[\n  42,\n  'Sally',\n  16.5\n]", S(ser));
}
 
开发者ID:irmen,项目名称:Serpent,代码行数:25,代码来源:SerializeTest.java

示例7: testCollection

import net.razorvine.serpent.Serializer; //导入依赖的package包/类
@Test
public void testCollection()
{
	Collection<Integer> intlist = new LinkedList<Integer>();
	intlist.add(42);
	intlist.add(43);
	Serializer serpent = new Serializer();
	byte[] ser = serpent.serialize(intlist);
	ser = strip_header(ser);
	assertEquals("[42,43]", S(ser));
	
	ser=strip_header(serpent.serialize(new int[] {42}));
	assertEquals("(42,)", S(ser));
	ser=strip_header(serpent.serialize(new int[] {42, 43}));
	assertEquals("(42,43)", S(ser));
	
	serpent.indent=true;
	ser = strip_header(serpent.serialize(intlist));
	assertEquals("[\n  42,\n  43\n]", S(ser));
	ser=strip_header(serpent.serialize(new int[] {42}));
	assertEquals("(\n  42,\n)", S(ser));
	ser=strip_header(serpent.serialize(new int[] {42, 43}));
	assertEquals("(\n  42,\n  43\n)", S(ser));
}
 
开发者ID:irmen,项目名称:Serpent,代码行数:25,代码来源:SerializeTest.java

示例8: testInterfaceHierarchyPickler

import net.razorvine.serpent.Serializer; //导入依赖的package包/类
@Test
public void testInterfaceHierarchyPickler()
{
	BaseClassWithInterface b = new BaseClassWithInterface();
	SubClassWithInterface sub = new SubClassWithInterface();
	Serializer serpent=new Serializer();
	byte[] data = serpent.serialize(b);
	assertEquals("{'__class__':'BaseClassWithInterface'}", S(strip_header(data)));  // the default serializer
	data = serpent.serialize(sub);
	assertEquals("{'__class__':'SubClassWithInterface'}", S(strip_header(data)));  // the default serializer

	Serializer.registerClass(IBaseInterface.class, new AnyClassConverter());
	data = serpent.serialize(b);
	assertEquals("{'(SUB)CLASS':'BaseClassWithInterface'}", S(strip_header(data)));  // custom serializer
	data = serpent.serialize(sub);
	assertEquals("{'(SUB)CLASS':'SubClassWithInterface'}", S(strip_header(data)));  // custom serializer
}
 
开发者ID:irmen,项目名称:Serpent,代码行数:18,代码来源:SerializeTest.java

示例9: testListOk

import net.razorvine.serpent.Serializer; //导入依赖的package包/类
@Test
public void testListOk()
{
	Serializer ser = new Serializer();
	LinkedList<Integer> t = new LinkedList<Integer>();
	t.add(1);
	t.add(2);
	t.add(3);
	LinkedList<Object> d = new LinkedList<Object>();
	d.add(t);
	d.add(t);
	d.add(t);
	byte[] data = ser.serialize(d);
	Parser parser = new Parser();
       parser.parse(data);
}
 
开发者ID:irmen,项目名称:Serpent,代码行数:17,代码来源:CycleTest.java

示例10: TestFloatPrecision

import net.razorvine.serpent.Serializer; //导入依赖的package包/类
@Test
public void TestFloatPrecision()
{
	Parser p = new Parser();
	Serializer serpent = new Serializer();
	byte[] ser = serpent.serialize(1.2345678987654321);
	DoubleNode dv = (DoubleNode) p.parse(ser).root;
	assertEquals(Double.valueOf(1.2345678987654321), dv.value);
	
	ser = serpent.serialize(5555.12345678987656);
	dv = (DoubleNode) p.parse(ser).root;
	assertEquals(Double.valueOf(5555.12345678987656), dv.value);

	ser = serpent.serialize(98765432123456.12345678987656);
	dv = (DoubleNode) p.parse(ser).root;
	assertEquals(Double.valueOf(98765432123456.12345678987656), dv.value);

	ser = serpent.serialize(98765432123456.12345678987656e+44);
	dv = (DoubleNode) p.parse(ser).root;
	assertEquals(Double.valueOf(98765432123456.12345678987656e+44), dv.value);
	
	ser = serpent.serialize(-98765432123456.12345678987656e-44);
	dv = (DoubleNode) p.parse(ser).root;
	assertEquals(Double.valueOf(-98765432123456.12345678987656e-44), dv.value);
}
 
开发者ID:irmen,项目名称:Serpent,代码行数:26,代码来源:ParserTest.java

示例11: testLongUnicodeRoundtrip

import net.razorvine.serpent.Serializer; //导入依赖的package包/类
@Test
public void testLongUnicodeRoundtrip()
{
	char[] chars64k = new char[65536];
	for(int i=0; i<=65535; ++i)
		chars64k[i]=(char)i;

	String str64k= new String(chars64k);
	
	Serializer ser=new Serializer();
	byte[] data = ser.serialize(str64k);
	assertTrue(data.length > chars64k.length);
	
	Parser p=new Parser();
	String result = (String)p.parse(data).getData();
	assertEquals(str64k, result);
}
 
开发者ID:irmen,项目名称:Serpent,代码行数:18,代码来源:ParserTest.java

示例12: testException

import net.razorvine.serpent.Serializer; //导入依赖的package包/类
@Test
public void testException()
{
	Serializer.registerClass(IllegalArgumentException.class, null);
	Exception x = new IllegalArgumentException("errormessage");
	Serializer serpent = new Serializer(true, true, false);
	byte[] ser = strip_header(serpent.serialize(x));
	assertEquals("{\n  '__class__': 'IllegalArgumentException',\n  '__exception__': True,\n  'args': (\n    'errormessage',\n  ),\n  'attributes': {}\n}", S(ser));
}
 
开发者ID:irmen,项目名称:Serpent,代码行数:10,代码来源:SerializeTest.java

示例13: testExceptionPackage

import net.razorvine.serpent.Serializer; //导入依赖的package包/类
@Test
public void testExceptionPackage()
{
	Serializer.registerClass(IllegalArgumentException.class, null);
	Exception x = new IllegalArgumentException("errormessage");
	Serializer serpent = new Serializer(true, true, true);
	byte[] ser = strip_header(serpent.serialize(x));
	assertEquals("{\n  '__class__': 'java.lang.IllegalArgumentException',\n  '__exception__': True,\n  'args': (\n    'errormessage',\n  ),\n  'attributes': {}\n}", S(ser));
}
 
开发者ID:irmen,项目名称:Serpent,代码行数:10,代码来源:SerializeTest.java

示例14: testNull

import net.razorvine.serpent.Serializer; //导入依赖的package包/类
@Test
public void testNull()
{
	Serializer ser = new Serializer();
	byte[] data = ser.serialize(null);
	data=strip_header(data);
	assertEquals("None", S(data));
}
 
开发者ID:irmen,项目名称:Serpent,代码行数:9,代码来源:SerializeTest.java

示例15: testStrings

import net.razorvine.serpent.Serializer; //导入依赖的package包/类
@Test
public void testStrings()
{
	Serializer serpent = new Serializer();
	byte[] ser = serpent.serialize("hello");
	byte[] data = strip_header(ser);
	assertEquals("'hello'", S(data));
  	ser = serpent.serialize("quotes'\"");
  	data = strip_header(ser);
  	assertEquals("'quotes\\'\"'", S(data));
  	ser = serpent.serialize("quotes2'");
  	data = strip_header(ser);
  	assertEquals("\"quotes2'\"", S(data));
}
 
开发者ID:irmen,项目名称:Serpent,代码行数:15,代码来源:SerializeTest.java


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