Package net.razorvine.pickle
Class Unpickler
- java.lang.Object
-
- net.razorvine.pickle.Unpickler
-
public class Unpickler extends java.lang.ObjectUnpickles an object graph from a pickle data inputstream. Supports all pickle protocol versions. Maps the python objects on the corresponding java equivalents or similar types. This class is NOT threadsafe! (Don't use the same pickler from different threads) See the README.txt for a table of the type mappings.- Author:
- Irmen de Jong (irmen@razorvine.net)
-
-
Field Summary
Fields Modifier and Type Field Description protected intHIGHEST_PROTOCOLThe highest Python Pickle protocol version supported by this library.protected java.io.InputStreaminputThe stream where the pickle data is read from.protected java.util.Map<java.lang.Integer,java.lang.Object>memoInternal cache of memoized objects.protected static java.lang.ObjectNO_RETURN_VALUEUsed as return value fordispatch(short)in the general case (because the object graph is built on the stack)protected static java.util.Map<java.lang.String,IObjectConstructor>objectConstructorsRegistry of object constructors that are used to create the appropriate Java objects for the given Python module.typename references.protected UnpickleStackstackThe stack that is used for building the resulting object graph.
-
Constructor Summary
Constructors Constructor Description Unpickler()Create an unpickler.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclose()Close the unpickler and frees the resources such as the unpickle stack and memo table.protected java.lang.Objectdispatch(short key)Process a single pickle stream opcode.java.lang.Objectload(java.io.InputStream stream)Read a pickled object representation from the given input stream.java.lang.Objectloads(byte[] pickledata)Read a pickled object representation from the given pickle data bytes.protected java.lang.Objectnext_buffer()Buffer support for protocol 5 out of band data If you want to unpickle such pickles, you'll have to subclass the unpickler and override this method to return the buffer data you want.protected java.lang.ObjectpersistentLoad(java.lang.String pid)Hook for the persistent id feature where an id is replaced externally by the appropriate object.static voidregisterConstructor(java.lang.String module, java.lang.String classname, IObjectConstructor constructor)Register additional object constructors for custom classes.
-
-
-
Field Detail
-
NO_RETURN_VALUE
protected static final java.lang.Object NO_RETURN_VALUE
Used as return value fordispatch(short)in the general case (because the object graph is built on the stack)
-
HIGHEST_PROTOCOL
protected final int HIGHEST_PROTOCOL
The highest Python Pickle protocol version supported by this library.- See Also:
- Constant Field Values
-
memo
protected java.util.Map<java.lang.Integer,java.lang.Object> memo
Internal cache of memoized objects.
-
stack
protected UnpickleStack stack
The stack that is used for building the resulting object graph.
-
input
protected java.io.InputStream input
The stream where the pickle data is read from.
-
objectConstructors
protected static java.util.Map<java.lang.String,IObjectConstructor> objectConstructors
Registry of object constructors that are used to create the appropriate Java objects for the given Python module.typename references.
-
-
Method Detail
-
registerConstructor
public static void registerConstructor(java.lang.String module, java.lang.String classname, IObjectConstructor constructor)Register additional object constructors for custom classes.
-
load
public java.lang.Object load(java.io.InputStream stream) throws PickleException, java.io.IOExceptionRead a pickled object representation from the given input stream.- Returns:
- the reconstituted object hierarchy specified in the file.
- Throws:
PickleExceptionjava.io.IOException
-
loads
public java.lang.Object loads(byte[] pickledata) throws PickleException, java.io.IOExceptionRead a pickled object representation from the given pickle data bytes.- Returns:
- the reconstituted object hierarchy specified in the file.
- Throws:
PickleExceptionjava.io.IOException
-
close
public void close()
Close the unpickler and frees the resources such as the unpickle stack and memo table.
-
next_buffer
protected java.lang.Object next_buffer() throws PickleException, java.io.IOExceptionBuffer support for protocol 5 out of band data If you want to unpickle such pickles, you'll have to subclass the unpickler and override this method to return the buffer data you want.- Throws:
PickleExceptionjava.io.IOException
-
dispatch
protected java.lang.Object dispatch(short key) throws PickleException, java.io.IOExceptionProcess a single pickle stream opcode.- Throws:
PickleExceptionjava.io.IOException
-
persistentLoad
protected java.lang.Object persistentLoad(java.lang.String pid)
Hook for the persistent id feature where an id is replaced externally by the appropriate object.- Parameters:
pid- the persistent id from the pickle- Returns:
- the actual object that belongs to that id. The default implementation throws a PickleException, telling you that you should implement this function yourself in a subclass of the Unpickler.
-
-