本文整理汇总了Java中net.razorvine.serpent.Serializer.serialize方法的典型用法代码示例。如果您正苦于以下问题:Java Serializer.serialize方法的具体用法?Java Serializer.serialize怎么用?Java Serializer.serialize使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.razorvine.serpent.Serializer
的用法示例。
在下文中一共展示了Serializer.serialize方法的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);
}
示例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);
}
示例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));
}
示例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));
}
示例5: 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);
}
示例6: 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);
}
示例7: 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));
}
示例8: 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));
}
示例9: testNullByte
import net.razorvine.serpent.Serializer; //导入方法依赖的package包/类
@Test
public void testNullByte()
{
Serializer serpent = new Serializer();
byte[] ser = serpent.serialize("null\u0000byte");
byte[] data = strip_header(ser);
assertEquals("'null\\x00byte'", new String(data));
for(byte b: ser) {
if(b==0)
fail("serialized data may not contain 0-bytes");
}
}
示例10: testBool
import net.razorvine.serpent.Serializer; //导入方法依赖的package包/类
@Test
public void testBool()
{
Serializer serpent = new Serializer();
byte[] ser = serpent.serialize(true);
byte[] data = strip_header(ser);
assertEquals("True", S(data));
ser = serpent.serialize(false);
data = strip_header(ser);
assertEquals("False", S(data));
}
示例11: testNumbers
import net.razorvine.serpent.Serializer; //导入方法依赖的package包/类
@Test
public void testNumbers()
{
Serializer serpent = new Serializer();
byte[] ser = serpent.serialize((int)12345);
byte[] data = strip_header(ser);
assertEquals("12345", S(data));
ser = serpent.serialize((long)1234567891234567891L);
data = strip_header(ser);
assertEquals("1234567891234567891", S(data));
ser = serpent.serialize(99.1234);
data = strip_header(ser);
assertEquals("99.1234", S(data));
ser = serpent.serialize(new BigInteger("1234999999999912345678901234567890"));
data = strip_header(ser);
assertEquals("1234999999999912345678901234567890", S(data));
ser = serpent.serialize(new BigDecimal("123456789.987654321987654321987654321987654321"));
data=strip_header(ser);
assertEquals("'123456789.987654321987654321987654321987654321'", S(data));
ComplexNumber cplx = new ComplexNumber(2.2, 3.3);
ser = serpent.serialize(cplx);
data = strip_header(ser);
assertEquals("(2.2+3.3j)", S(data));
cplx = new ComplexNumber(0, 3);
ser = serpent.serialize(cplx);
data = strip_header(ser);
assertEquals("(0.0+3.0j)", S(data));
cplx = new ComplexNumber(-2, -3);
ser = serpent.serialize(cplx);
data = strip_header(ser);
assertEquals("(-2.0-3.0j)", S(data));
cplx = new ComplexNumber(-2.5, -3.9);
ser = serpent.serialize(cplx);
data = strip_header(ser);
assertEquals("(-2.5-3.9j)", S(data));
}
示例12: testClassFail
import net.razorvine.serpent.Serializer; //导入方法依赖的package包/类
@Test(expected = IllegalArgumentException.class)
public void testClassFail()
{
Serializer serpent = new Serializer(true, true, false);
Object obj = new UnserializableClass();
serpent.serialize(obj);
}
示例13: testMaxLevel
import net.razorvine.serpent.Serializer; //导入方法依赖的package包/类
@Test
public void testMaxLevel()
{
Serializer ser = new Serializer();
assertEquals(500, ser.maximumLevel);
Object[] array = new Object[] {
"level1",
new Object[] {
"level2",
new Object[] {
"level3",
new Object[] {
"level 4"
}
}
}
};
ser.maximumLevel = 4;
ser.serialize(array); // should work
ser.maximumLevel = 3;
try {
ser.serialize(array);
fail("should fail");
} catch(IllegalArgumentException x) {
assertTrue(x.getMessage().contains("too deep"));
}
}
示例14: testAbstractBaseClassHierarchyPickler
import net.razorvine.serpent.Serializer; //导入方法依赖的package包/类
@Test
public void testAbstractBaseClassHierarchyPickler()
{
ConcreteSubClass c = new ConcreteSubClass();
Serializer serpent=new Serializer();
byte[] data = serpent.serialize(c);
assertEquals("{'__class__':'ConcreteSubClass'}", S(strip_header(data))); // the default serializer
Serializer.registerClass(AbstractBaseClass.class, new AnyClassConverter());
data = serpent.serialize(c);
assertEquals("{'(SUB)CLASS':'ConcreteSubClass'}", S(strip_header(data))); // custom serializer
}
示例15: testClassCycle
import net.razorvine.serpent.Serializer; //导入方法依赖的package包/类
@Test(expected=IllegalArgumentException.class)
public void testClassCycle()
{
Serializer ser = new Serializer();
SerializationHelperClass thing = new SerializationHelperClass();
thing.i = 42;
thing.s = "hello";
thing.x = 99;
thing.obj = thing;
ser.serialize(thing);
}