本文整理汇总了Java中net.razorvine.pyro.serializer.PickleSerializer类的典型用法代码示例。如果您正苦于以下问题:Java PickleSerializer类的具体用法?Java PickleSerializer怎么用?Java PickleSerializer使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
PickleSerializer类属于net.razorvine.pyro.serializer包,在下文中一共展示了PickleSerializer类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testUnpickleMemo
import net.razorvine.pyro.serializer.PickleSerializer; //导入依赖的package包/类
@Test
public void testUnpickleMemo() throws PickleException, IOException {
// the pickle is of the following list: [65, 'hello', 'hello', {'recurse': [...]}, 'hello']
// i.e. the 4th element is a dict referring back to the list itself and the 'hello' strings are reused
byte[] pickle = new byte[]
{(byte) 128, 2, 93, 113, 0, 40, 75, 65, 85, 5, 104, 101, 108, 108, 111, 113, 1, 104, 1, 125, 113, 2,
85, 7, 114, 101, 99, 117, 114, 115, 101, 113, 3, 104, 0, 115, 104, 1, 101, 46};
PyroSerializer ser = new PickleSerializer();
ArrayList<Object> a = (ArrayList<Object>) ser.deserializeData(pickle);
assertEquals(5, a.size());
assertEquals(65, a.get(0));
assertEquals("hello", a.get(1));
assertSame(a.get(1), a.get(2));
assertSame(a.get(1), a.get(4));
HashMap<String, Object> h = (HashMap<String,Object>) a.get(3);
assertSame(a, h.get("recurse"));
}
示例2: testUnpickleUnsupportedClass
import net.razorvine.pyro.serializer.PickleSerializer; //导入依赖的package包/类
@Test
public void testUnpickleUnsupportedClass() throws IOException {
// an unsupported class is mapped to a dictionary containing the class's attributes, and a __class__ attribute with the name of the class
byte[] pickled = new byte[] {
(byte)128, 2, 99, 95, 95, 109, 97, 105, 110, 95, 95, 10, 67, 117, 115, 116, 111, 109, 67, 108,
97, 115, 115, 10, 113, 0, 41, (byte)129, 113, 1, 125, 113, 2, 40, 85, 3, 97, 103, 101, 113, 3,
75, 34, 85, 6, 118, 97, 108, 117, 101, 115, 113, 4, 93, 113, 5, 40, 75, 1, 75, 2, 75, 3,
101, 85, 4, 110, 97, 109, 101, 113, 6, 85, 5, 72, 97, 114, 114, 121, 113, 7, 117, 98, 46};
PyroSerializer ser = new PickleSerializer();
Map<String, Object> o = (Map<String, Object>) ser.deserializeData(pickled);
assertEquals(4, o.size());
assertEquals("Harry", o.get("name"));
assertEquals(34, o.get("age"));
ArrayList<Object> expected = new ArrayList<Object>() {{
add(1);
add(2);
add(3);
}};
assertEquals(expected, o.get("values"));
assertEquals("__main__.CustomClass", o.get("__class__"));
}
示例3: testUnpickleCustomClassAsClassDict
import net.razorvine.pyro.serializer.PickleSerializer; //导入依赖的package包/类
@Test
public void testUnpickleCustomClassAsClassDict() throws IOException {
byte[] pickled = new byte[] {
(byte)128, 2, 99, 95, 95, 109, 97, 105, 110, 95, 95, 10, 67, 117, 115, 115, 115, 115, 115, 115,
97, 122, 122, 10, 113, 0, 41, (byte)129, 113, 1, 125, 113, 2, 40, 85, 3, 97, 103, 101, 113, 3,
75, 34, 85, 6, 118, 97, 108, 117, 101, 115, 113, 4, 93, 113, 5, 40, 75, 1, 75, 2, 75, 3,
101, 85, 4, 110, 97, 109, 101, 113, 6, 85, 5, 72, 97, 114, 114, 121, 113, 7, 117, 98, 46};
PyroSerializer ser = new PickleSerializer();
ClassDict cd = (ClassDict) ser.deserializeData(pickled);
assertEquals("__main__.Cussssssazz", cd.get("__class__"));
assertEquals("Harry", cd.get("name"));
assertEquals(34, cd.get("age"));
ArrayList<Object> expected = new ArrayList<Object>() {{
add(1);
add(2);
add(3);
}};
assertEquals(expected, cd.get("values"));
}
示例4: testUnpickleCustomClass
import net.razorvine.pyro.serializer.PickleSerializer; //导入依赖的package包/类
@Test
public void testUnpickleCustomClass() throws IOException {
byte[] pickled = new byte[] {
(byte)128, 2, 99, 95, 95, 109, 97, 105, 110, 95, 95, 10, 67, 117, 115, 116, 111, 109, 67, 108,
97, 122, 122, 10, 113, 0, 41, (byte)129, 113, 1, 125, 113, 2, 40, 85, 3, 97, 103, 101, 113, 3,
75, 34, 85, 6, 118, 97, 108, 117, 101, 115, 113, 4, 93, 113, 5, 40, 75, 1, 75, 2, 75, 3,
101, 85, 4, 110, 97, 109, 101, 113, 6, 85, 5, 72, 97, 114, 114, 121, 113, 7, 117, 98, 46};
Unpickler.registerConstructor("__main__","CustomClazz", new CustomClazzConstructor());
PyroSerializer ser = new PickleSerializer();
CustomClazz o = (CustomClazz) ser.deserializeData(pickled);
assertEquals("Harry" ,o.name);
assertEquals(34 ,o.age);
ArrayList<Object> expected = new ArrayList<Object>() {{
add(1);
add(2);
add(3);
}};
assertEquals(expected, o.values);
}
示例5: testUnpickleException
import net.razorvine.pyro.serializer.PickleSerializer; //导入依赖的package包/类
@Test
public void testUnpickleException() throws IOException {
PyroSerializer ser = new PickleSerializer();
// python 2.x
PythonException x = (PythonException) ser.deserializeData("cexceptions\nZeroDivisionError\np0\n(S'hello'\np1\ntp2\nRp3\n.".getBytes());
assertEquals("hello", x.getMessage());
// python 3.x
x = (PythonException) ser.deserializeData("c__builtin__\nZeroDivisionError\np0\n(Vhello\np1\ntp2\nRp3\n.".getBytes());
assertEquals("hello", x.getMessage());
x = (PythonException) ser.deserializeData("cbuiltins\nZeroDivisionError\np0\n(Vhello\np1\ntp2\nRp3\n.".getBytes());
assertEquals("hello", x.getMessage());
// python 2.x
x = (PythonException) ser.deserializeData("cexceptions\nGeneratorExit\np0\n(tRp1\n.".getBytes());
assertNull(x.getMessage());
// python 3.x
x = (PythonException) ser.deserializeData("c__builtin__\nGeneratorExit\np0\n(tRp1\n.".getBytes());
assertNull(x.getMessage());
x = (PythonException) ser.deserializeData("cbuiltins\nGeneratorExit\np0\n(tRp1\n.".getBytes());
assertNull(x.getMessage());
}
示例6: apply
import net.razorvine.pyro.serializer.PickleSerializer; //导入依赖的package包/类
@Override
public Object apply(WarpScriptStack stack) throws WarpScriptException {
Object o = stack.pop();
if (!(o instanceof byte[])) {
throw new WarpScriptException(getName() + " expects a byte array on top of the stack.");
}
try {
PickleSerializer serializer = new PickleSerializer();
Object out = serializer.deserializeData((byte[]) o);
stack.push(out);
} catch (IOException ioe) {
throw new WarpScriptException(ioe);
}
return stack;
}
示例7: testUnpickleProto0Bytes
import net.razorvine.pyro.serializer.PickleSerializer; //导入依赖的package包/类
@Test
public void testUnpickleProto0Bytes() throws IOException, NoSuchAlgorithmException {
InputStream is = this.getClass().getResourceAsStream("pickled_bytes_level0.dat");
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int c;
while((c = is.read())>=0) bos.write(c);
is.close();
byte[] pickle = bos.toByteArray();
PickleSerializer ser = new PickleSerializer();
String x = (String)ser.deserializeData(pickle);
assertEquals(2496, x.length());
// validate that the bytes in the string are what we expect (based on md5 hash)
MessageDigest m = MessageDigest.getInstance("SHA1");
m.update(x.getBytes("utf-8"));
BigInteger digest = new BigInteger(1, m.digest());
assertEquals("22f45b876383c91b1cb20afe51ee3b30f5a85d4c", digest.toString(16));
}
示例8: testPyroClassesPickle
import net.razorvine.pyro.serializer.PickleSerializer; //导入依赖的package包/类
@Test
public void testPyroClassesPickle() throws IOException
{
PickleSerializer pickler = new PickleSerializer();
PyroURI uri = new PyroURI("PYRO:[email protected]:4444");
byte[] s = pickler.serializeData(uri);
Object x = pickler.deserializeData(s);
assertEquals(uri, x);
PyroProxy proxy = new PyroProxy(uri);
proxy.correlation_id = UUID.randomUUID();
proxy.pyroHmacKey = "secret".getBytes();
proxy.pyroHandshake = "apples";
proxy.pyroAttrs = new HashSet<String>();
proxy.pyroAttrs.add("attr1");
proxy.pyroAttrs.add("attr2");
s = pickler.serializeData(proxy);
x = pickler.deserializeData(s);
PyroProxy proxy2 = (PyroProxy) x;
assertEquals(uri.host, proxy2.hostname);
assertEquals(uri.objectid, proxy2.objectid);
assertEquals(uri.port, proxy2.port);
assertNull(proxy2.correlation_id); // correlation_id is not serialized on the proxy object")
assertEquals(proxy.pyroHandshake, proxy2.pyroHandshake);
assertArrayEquals(proxy.pyroHmacKey, proxy2.pyroHmacKey);
assertEquals(2, proxy2.pyroAttrs.size());
assertEquals(proxy.pyroAttrs, proxy2.pyroAttrs);
PyroException ex = new PyroException("error");
ex._pyroTraceback = "traceback";
s = pickler.serializeData(ex);
x = pickler.deserializeData(s);
PyroException ex2 = (PyroException) x;
assertEquals(ex.getMessage(), ex2.getMessage());
assertEquals("traceback", ex2._pyroTraceback);
}
示例9: testCompareLibVersions
import net.razorvine.pyro.serializer.PickleSerializer; //导入依赖的package包/类
@Test
public void testCompareLibVersions()
{
assertEquals(-1, PickleSerializer.compareLibraryVersions("1.2", "2"));
assertEquals(-1, PickleSerializer.compareLibraryVersions("1.2", "2.5.6"));
assertEquals(0, PickleSerializer.compareLibraryVersions("1.2", "1.2"));
assertEquals(1, PickleSerializer.compareLibraryVersions("2", "1.2"));
assertEquals(1, PickleSerializer.compareLibraryVersions("2.54.66", "1.2.3.4.99"));
}
示例10: testPickleUnpickleProxy
import net.razorvine.pyro.serializer.PickleSerializer; //导入依赖的package包/类
@Test
public void testPickleUnpickleProxy() throws IOException {
PyroProxy proxy=new PyroProxy("hostname",9999,"objectid");
proxy.pyroHmacKey = "secret".getBytes();
PyroSerializer ser = new PickleSerializer();
byte[] pickled_proxy=ser.serializeData(proxy);
PyroProxy result = (PyroProxy) ser.deserializeData(pickled_proxy);
assertEquals(proxy.hostname, result.hostname);
assertEquals(proxy.objectid, result.objectid);
assertEquals(proxy.port, result.port);
assertArrayEquals("secret".getBytes(), result.pyroHmacKey);
}
示例11: unpickleRealProxy
import net.razorvine.pyro.serializer.PickleSerializer; //导入依赖的package包/类
private void unpickleRealProxy(String pickle_name) throws IOException
{
InputStream is = this.getClass().getResourceAsStream(pickle_name);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int c;
while((c = is.read())>=0) bos.write(c);
is.close();
byte[] pickled_proxy = bos.toByteArray();
PyroSerializer ser = new PickleSerializer();
PyroProxy proxy=(PyroProxy)ser.deserializeData(pickled_proxy);
assertEquals("Pyro.NameServer",proxy.objectid);
assertEquals("localhost",proxy.hostname);
assertEquals(9090,proxy.port);
assertEquals("hello", proxy.pyroHandshake);
assertArrayEquals("secret".getBytes(), proxy.pyroHmacKey);
Set<String> expectedSet = new HashSet<String>();
assertEquals(expectedSet, proxy.pyroAttrs);
expectedSet.clear();
expectedSet.add("lookup");
expectedSet.add("ping");
expectedSet.add("register");
expectedSet.add("remove");
expectedSet.add("list");
expectedSet.add("count");
assertEquals(expectedSet, proxy.pyroMethods);
expectedSet = new HashSet<String>();
assertEquals(expectedSet, proxy.pyroOneway);
}
示例12: apply
import net.razorvine.pyro.serializer.PickleSerializer; //导入依赖的package包/类
@Override
public Object apply(WarpScriptStack stack) throws WarpScriptException {
Object o = stack.pop();
try {
PickleSerializer serializer = new PickleSerializer();
byte[] data = serializer.serializeData(o);
stack.push(data);
} catch (IOException ioe) {
throw new WarpScriptException(ioe);
}
return stack;
}
示例13: testPyroClassesPickle
import net.razorvine.pyro.serializer.PickleSerializer; //导入依赖的package包/类
@Test
public void testPyroClassesPickle() throws IOException
{
PickleSerializer pickler = new PickleSerializer();
PyroURI uri = new PyroURI("PYRO:[email protected]:4444");
byte[] s = pickler.serializeData(uri);
Object x = pickler.deserializeData(s);
assertEquals(uri, x);
PyroProxy proxy = new PyroProxy(uri);
proxy.correlation_id = UUID.randomUUID();
proxy.pyroHmacKey = "secret".getBytes();
proxy.pyroHandshake = "apples";
proxy.pyroAttrs = new HashSet<String>();
proxy.pyroAttrs.add("attr1");
proxy.pyroAttrs.add("attr2");
s = pickler.serializeData(proxy);
x = pickler.deserializeData(s);
PyroProxy proxy2 = (PyroProxy) x;
assertEquals(uri.host, proxy2.hostname);
assertEquals(uri.objectid, proxy2.objectid);
assertEquals(uri.port, proxy2.port);
assertNull(proxy2.correlation_id); // correlation_id is not serialized on the proxy object")
assertEquals(proxy.pyroHandshake, proxy2.pyroHandshake);
assertArrayEquals(proxy.pyroHmacKey, proxy2.pyroHmacKey);
assertEquals(2, proxy2.pyroAttrs.size());
assertEquals(proxy.pyroAttrs, proxy2.pyroAttrs);
PyroException ex = new PyroException("error");
ex._pyroTraceback = "traceback";
s = pickler.serializeData(ex);
x = pickler.deserializeData(s);
PyroException ex2 = (PyroException) x;
assertEquals("[Pyro4.errors.PyroError] error", ex2.getMessage());
assertEquals("traceback", ex2._pyroTraceback);
}
示例14: unpickleRealProxy
import net.razorvine.pyro.serializer.PickleSerializer; //导入依赖的package包/类
private void unpickleRealProxy(String pickle_name) throws IOException
{
InputStream is = this.getClass().getResourceAsStream(pickle_name);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
int c;
while((c = is.read())>=0) bos.write(c);
is.close();
byte[] pickled_proxy = bos.toByteArray();
PyroSerializer ser = new PickleSerializer();
PyroProxy proxy=(PyroProxy)ser.deserializeData(pickled_proxy);
assertEquals("Pyro.NameServer",proxy.objectid);
assertEquals("localhost",proxy.hostname);
assertEquals(9090,proxy.port);
assertEquals("hello", proxy.pyroHandshake);
assertArrayEquals("secret".getBytes(), proxy.pyroHmacKey);
Set<String> expectedSet = new HashSet<String>();
assertEquals(expectedSet, proxy.pyroAttrs);
expectedSet.clear();
expectedSet.add("lookup");
expectedSet.add("ping");
expectedSet.add("register");
expectedSet.add("remove");
expectedSet.add("list");
expectedSet.add("count");
expectedSet.add("set_metadata");
proxy.pyroMethods.removeAll(expectedSet);
assertEquals(0, proxy.pyroMethods.size());
expectedSet = new HashSet<String>();
assertEquals(expectedSet, proxy.pyroOneway);
}
示例15: testUnpickleException
import net.razorvine.pyro.serializer.PickleSerializer; //导入依赖的package包/类
@Test
public void testUnpickleException() throws IOException {
PyroSerializer ser = new PickleSerializer();
// python 2.x
PythonException x = (PythonException) ser.deserializeData("cexceptions\nZeroDivisionError\np0\n(S'hello'\np1\ntp2\nRp3\n.".getBytes());
assertEquals("[exceptions.ZeroDivisionError] hello", x.getMessage());
assertEquals("exceptions.ZeroDivisionError", x.pythonExceptionType);
// python 3.x
x = (PythonException) ser.deserializeData("c__builtin__\nZeroDivisionError\np0\n(Vhello\np1\ntp2\nRp3\n.".getBytes());
assertEquals("[__builtin__.ZeroDivisionError] hello", x.getMessage());
assertEquals("__builtin__.ZeroDivisionError", x.pythonExceptionType);
x = (PythonException) ser.deserializeData("cbuiltins\nZeroDivisionError\np0\n(Vhello\np1\ntp2\nRp3\n.".getBytes());
assertEquals("[builtins.ZeroDivisionError] hello", x.getMessage());
assertEquals("builtins.ZeroDivisionError", x.pythonExceptionType);
// python 2.x
x = (PythonException) ser.deserializeData("cexceptions\nGeneratorExit\np0\n(tRp1\n.".getBytes());
assertEquals("[exceptions.GeneratorExit]", x.getMessage());
assertEquals("exceptions.GeneratorExit", x.pythonExceptionType);
// python 3.x
x = (PythonException) ser.deserializeData("c__builtin__\nGeneratorExit\np0\n(tRp1\n.".getBytes());
assertEquals("[__builtin__.GeneratorExit]", x.getMessage());
assertEquals("__builtin__.GeneratorExit", x.pythonExceptionType);
x = (PythonException) ser.deserializeData("cbuiltins\nGeneratorExit\np0\n(tRp1\n.".getBytes());
assertEquals("[builtins.GeneratorExit]", x.getMessage());
assertEquals("builtins.GeneratorExit", x.pythonExceptionType);
}