Package jadex.binary
Class AbstractDecodingContext
- java.lang.Object
-
- jadex.binary.AbstractDecodingContext
-
- All Implemented Interfaces:
IDecodingContext
,IUserContextContainer
- Direct Known Subclasses:
DataInputDecodingContext
,StreamDecodingContext
public abstract class AbstractDecodingContext extends java.lang.Object implements IDecodingContext
Abstract base class for decoding context.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected static interface
AbstractDecodingContext.IVersionedHandler
Interface for versioned operations.protected class
AbstractDecodingContext.VersionedHandler2
Operations for format version 2.protected class
AbstractDecodingContext.VersionedHandler3
Operations for format version 3.protected class
AbstractDecodingContext.VersionedHandler4
Operations for format version 4.
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.ClassLoader
classloader
The classloaderprotected java.util.List<java.lang.String>
classnamepool
The class name pool.protected SerializationConfig
config
The serialization config.protected java.lang.String
currentclassname
The current class name.protected java.util.List<IDecoderHandler>
decoderhandlers
The decoder handlers.protected IErrorReporter
errorreporter
Error Reporterprotected BiHashMap<java.lang.Long,java.lang.Object>
knownobjects
protected java.lang.Object
lastobject
The last decoded objectprotected java.util.List<ITraverseProcessor>
postprocessors
The postprocessors.protected java.util.List<java.lang.String>
stringpool
The String pool.protected java.lang.Object
usercontext
A user context.protected AbstractDecodingContext.IVersionedHandler
versionedhandler
Handler for versioned operations.
-
Constructor Summary
Constructors Constructor Description AbstractDecodingContext(java.util.List<IDecoderHandler> decoderhandlers, java.util.List<ITraverseProcessor> postprocessors, java.lang.Object usercontext, java.lang.ClassLoader classloader, IErrorReporter errorreporter, SerializationConfig config)
Initializes the context.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description long
createObjectId(java.lang.Object object)
Creates ID for an object.java.lang.ClassLoader
getClassloader()
Gets the classloader.java.lang.String
getCurrentClassName()
Gets the current class name.java.util.List<IDecoderHandler>
getDecoderHandlers()
Returns the handlers used to decode objects.IErrorReporter
getErrorReporter()
Gets the error reporter.java.lang.Object
getLastObject()
Returns the last object decoded.java.lang.Object
getObjectForId(long id)
Gets a known object by ID.java.lang.Long
getObjectId(java.lang.Object object)
Gets the ID of a known object.java.util.List<ITraverseProcessor>
getPostProcessors()
Returns the handlers used for post-processing.java.lang.Object
getUserContext()
Returns the user context.java.lang.String
pooledRead(java.util.List<java.lang.String> pool)
Readsa a string using a pool.abstract byte[]
read(byte[] array)
Reads a number of bytes from the buffer and fills the array.abstract byte[]
read(byte[] array, int woffset, int wlength)
Reads a number of bytes from the buffer and fills the array.abstract byte[]
read(int count)
Reads a number of bytes from the buffer.boolean
readBoolean()
Reads a boolean value from the buffer.java.lang.String
readClassname()
Helper method for decoding a class name.long
readSignedVarInt()
Helper method for decoding a signed variable-sized integer (VarInt).java.lang.String
readString()
Helper method for decoding a string.long
readVarInt()
Helper method for decoding a variable-sized integer (VarInt).protected void
setCurrentClassName(java.lang.String currentclassname)
Sets the current class name.void
setLastObject(java.lang.Object lastobject)
Sets the last object decoded.void
setObjectForId(long id, java.lang.Object object)
Sets a known object by ID.void
setVersion(int version)
Sets the format version.void
startObjectFrame()
Starts an object frame when using a context with framing support.void
startObjectFrame(boolean fixedsize)
Starts an object frame when using a context with framing support.void
stopObjectFrame()
Stops an object frame when using a context with framing support.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface jadex.binary.IDecodingContext
getCurrentOffset, readByte
-
-
-
-
Field Detail
-
classloader
protected java.lang.ClassLoader classloader
The classloader
-
decoderhandlers
protected java.util.List<IDecoderHandler> decoderhandlers
The decoder handlers.
-
versionedhandler
protected AbstractDecodingContext.IVersionedHandler versionedhandler
Handler for versioned operations.
-
stringpool
protected java.util.List<java.lang.String> stringpool
The String pool.
-
classnamepool
protected java.util.List<java.lang.String> classnamepool
The class name pool.
-
usercontext
protected java.lang.Object usercontext
A user context.
-
postprocessors
protected java.util.List<ITraverseProcessor> postprocessors
The postprocessors.
-
lastobject
protected java.lang.Object lastobject
The last decoded object
-
currentclassname
protected java.lang.String currentclassname
The current class name.
-
errorreporter
protected IErrorReporter errorreporter
Error Reporter
-
knownobjects
protected BiHashMap<java.lang.Long,java.lang.Object> knownobjects
-
config
protected SerializationConfig config
The serialization config.
-
-
Constructor Detail
-
AbstractDecodingContext
public AbstractDecodingContext(java.util.List<IDecoderHandler> decoderhandlers, java.util.List<ITraverseProcessor> postprocessors, java.lang.Object usercontext, java.lang.ClassLoader classloader, IErrorReporter errorreporter, SerializationConfig config)
Initializes the context.
-
-
Method Detail
-
getClassloader
public java.lang.ClassLoader getClassloader()
Gets the classloader.- Specified by:
getClassloader
in interfaceIDecodingContext
- Returns:
- The classloader.
-
getDecoderHandlers
public java.util.List<IDecoderHandler> getDecoderHandlers()
Returns the handlers used to decode objects.- Specified by:
getDecoderHandlers
in interfaceIDecodingContext
- Returns:
- The handlers.
-
getPostProcessors
public java.util.List<ITraverseProcessor> getPostProcessors()
Returns the handlers used for post-processing.- Specified by:
getPostProcessors
in interfaceIDecodingContext
- Returns:
- Post-processing handlers.
-
createObjectId
public long createObjectId(java.lang.Object object)
Creates ID for an object.- Specified by:
createObjectId
in interfaceIDecodingContext
- Parameters:
object
- The object- Returns:
- The ID.
-
getObjectForId
public java.lang.Object getObjectForId(long id)
Gets a known object by ID.- Specified by:
getObjectForId
in interfaceIDecodingContext
- Parameters:
id
- The ID.- Returns:
- The object or null.
-
setObjectForId
public void setObjectForId(long id, java.lang.Object object)
Sets a known object by ID.- Specified by:
setObjectForId
in interfaceIDecodingContext
- Parameters:
id
- The ID.object
- The object..
-
getObjectId
public java.lang.Long getObjectId(java.lang.Object object)
Gets the ID of a known object.- Specified by:
getObjectId
in interfaceIDecodingContext
- Parameters:
object
- The object- Returns:
- The ID.
-
getUserContext
public java.lang.Object getUserContext()
Returns the user context.- Specified by:
getUserContext
in interfaceIUserContextContainer
- Returns:
- The user context.
-
getErrorReporter
public IErrorReporter getErrorReporter()
Gets the error reporter.- Specified by:
getErrorReporter
in interfaceIDecodingContext
- Returns:
- The error reporter.
-
getLastObject
public java.lang.Object getLastObject()
Returns the last object decoded.- Specified by:
getLastObject
in interfaceIDecodingContext
- Returns:
- The last object decoded.
-
setLastObject
public void setLastObject(java.lang.Object lastobject)
Sets the last object decoded.- Specified by:
setLastObject
in interfaceIDecodingContext
- Parameters:
lastobject
- The last object decoded.
-
readBoolean
public boolean readBoolean()
Reads a boolean value from the buffer.- Specified by:
readBoolean
in interfaceIDecodingContext
- Returns:
- Boolean value.
-
readString
public java.lang.String readString()
Helper method for decoding a string.- Specified by:
readString
in interfaceIDecodingContext
- Returns:
- String encoded at the current position.
-
readVarInt
public long readVarInt()
Helper method for decoding a variable-sized integer (VarInt).- Specified by:
readVarInt
in interfaceIDecodingContext
- Returns:
- The decoded value.
-
readSignedVarInt
public long readSignedVarInt()
Helper method for decoding a signed variable-sized integer (VarInt).- Specified by:
readSignedVarInt
in interfaceIDecodingContext
- Returns:
- The decoded value.
-
readClassname
public java.lang.String readClassname()
Helper method for decoding a class name.- Specified by:
readClassname
in interfaceIDecodingContext
- Returns:
- String encoded at the current position.
-
pooledRead
public java.lang.String pooledRead(java.util.List<java.lang.String> pool)
Readsa a string using a pool.- Parameters:
pool
- The pool.- Returns:
- The string.
-
getCurrentClassName
public java.lang.String getCurrentClassName()
Gets the current class name.- Specified by:
getCurrentClassName
in interfaceIDecodingContext
- Returns:
- The current class name.
-
setCurrentClassName
protected void setCurrentClassName(java.lang.String currentclassname)
Sets the current class name.
-
setVersion
public void setVersion(int version)
Sets the format version.- Specified by:
setVersion
in interfaceIDecodingContext
- Parameters:
version
- The version.
-
startObjectFrame
public void startObjectFrame()
Starts an object frame when using a context with framing support.
-
startObjectFrame
public void startObjectFrame(boolean fixedsize)
Starts an object frame when using a context with framing support.- Specified by:
startObjectFrame
in interfaceIDecodingContext
- Parameters:
fixedsize
- If true, use fixed-size (integer) framing. Set true if the object being framed is expected to be larger than 127 bytes (same type of object MUST use either fixed OR variable framing).
-
stopObjectFrame
public void stopObjectFrame()
Stops an object frame when using a context with framing support.- Specified by:
stopObjectFrame
in interfaceIDecodingContext
-
read
public abstract byte[] read(int count)
Reads a number of bytes from the buffer.- Parameters:
count
- Number of bytes.- Returns:
- Byte array with the bytes.
-
read
public abstract byte[] read(byte[] array)
Reads a number of bytes from the buffer and fills the array.- Specified by:
read
in interfaceIDecodingContext
- Parameters:
array
- The byte array.- Returns:
- The byte array for convenience.
-
read
public abstract byte[] read(byte[] array, int woffset, int wlength)
Reads a number of bytes from the buffer and fills the array.- Parameters:
array
- The byte array.woffset
- write offset.wlength
- length to read.- Returns:
- The byte array for convenience.
-
-