net.razorvine.pickle.objects.ByteArrayConstructor 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.pickle.objects;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import net.razorvine.pickle.IObjectConstructor;
import net.razorvine.pickle.PickleException;
/**
* Creates byte arrays (byte[]).
*
* @author Irmen de Jong ([email protected])
*/
public class ByteArrayConstructor implements IObjectConstructor {
public Object construct(Object[] args) throws PickleException {
// args for bytearray constructor: [ String string, String encoding ]
// args for bytearray constructor (from python3 bytes): [ ArrayList ] or just [byte[]] (when it uses BINBYTES opcode)
if (args.length != 1 && args.length != 2)
throw new PickleException("invalid pickle data for bytearray; expected 1 or 2 args, got "+args.length);
if(args.length==1) {
if(args[0] instanceof byte[]) {
return args[0];
}
@SuppressWarnings("unchecked")
ArrayListvalues=(ArrayList)args[0];
byte[] data=new byte[values.size()];
for(int i=0; i
© 2015 - 2025 Weber Informatics LLC | Privacy Policy