net.razorvine.pyro.serializer.PyroExceptionPickler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pyrolite Show documentation
Show all versions of pyrolite Show documentation
This library allows your Java program to interface very easily with the Python world. It uses the Pyro protocol to call methods on remote objects. (See https://pyro5.readthedocs.io/).
Pyrolite only implements part of the client side Pyro library, hence its name 'lite'... So if you don't need Pyro's full feature set, Pyrolite may be a good choice to connect java or .NET and python.
Version 5.0 changes: support Pyro5 wire protocol. Dropped support of Pyro4 (stick to version 4.xx for that).
package net.razorvine.pyro.serializer;
import java.io.IOException;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.Map;
import net.razorvine.pickle.IObjectPickler;
import net.razorvine.pickle.Opcodes;
import net.razorvine.pickle.PickleException;
import net.razorvine.pickle.Pickler;
import net.razorvine.pyro.PyroException;
/**
* Pickler extension to be able to pickle PyroException objects.
*
* @author Irmen de Jong ([email protected])
*/
public class PyroExceptionPickler implements IObjectPickler {
public void pickle(Object o, OutputStream out, Pickler currentPickler) throws PickleException, IOException {
PyroException error = (PyroException) o;
out.write(Opcodes.GLOBAL);
byte[] output="Pyro4.errors\nPyroError\n".getBytes();
out.write(output,0,output.length);
Object[] args = new Object[] { error.getMessage() };
currentPickler.save(args);
out.write(Opcodes.REDUCE);
if(error._pyroTraceback!=null)
{
// add _pyroTraceback attribute to the output
Map tb = new HashMap();
tb.put("_pyroTraceback", new String[]{ error._pyroTraceback }); // transform single string back into list
currentPickler.save(tb);
out.write(Opcodes.BUILD);
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy