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 interfaceAbstractDecodingContext.IVersionedHandlerInterface for versioned operations.protected classAbstractDecodingContext.VersionedHandler2Operations for format version 2.protected classAbstractDecodingContext.VersionedHandler3Operations for format version 3.protected classAbstractDecodingContext.VersionedHandler4Operations for format version 4.
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.ClassLoaderclassloaderThe classloaderprotected java.util.List<java.lang.String>classnamepoolThe class name pool.protected SerializationConfigconfigThe serialization config.protected java.lang.StringcurrentclassnameThe current class name.protected java.util.List<IDecoderHandler>decoderhandlersThe decoder handlers.protected IErrorReportererrorreporterError Reporterprotected BiHashMap<java.lang.Long,java.lang.Object>knownobjectsprotected java.lang.ObjectlastobjectThe last decoded objectprotected java.util.List<ITraverseProcessor>postprocessorsThe postprocessors.protected java.util.List<java.lang.String>stringpoolThe String pool.protected java.lang.ObjectusercontextA user context.protected AbstractDecodingContext.IVersionedHandlerversionedhandlerHandler 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 longcreateObjectId(java.lang.Object object)Creates ID for an object.java.lang.ClassLoadergetClassloader()Gets the classloader.java.lang.StringgetCurrentClassName()Gets the current class name.java.util.List<IDecoderHandler>getDecoderHandlers()Returns the handlers used to decode objects.IErrorReportergetErrorReporter()Gets the error reporter.java.lang.ObjectgetLastObject()Returns the last object decoded.java.lang.ObjectgetObjectForId(long id)Gets a known object by ID.java.lang.LonggetObjectId(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.ObjectgetUserContext()Returns the user context.java.lang.StringpooledRead(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.booleanreadBoolean()Reads a boolean value from the buffer.java.lang.StringreadClassname()Helper method for decoding a class name.longreadSignedVarInt()Helper method for decoding a signed variable-sized integer (VarInt).java.lang.StringreadString()Helper method for decoding a string.longreadVarInt()Helper method for decoding a variable-sized integer (VarInt).protected voidsetCurrentClassName(java.lang.String currentclassname)Sets the current class name.voidsetLastObject(java.lang.Object lastobject)Sets the last object decoded.voidsetObjectForId(long id, java.lang.Object object)Sets a known object by ID.voidsetVersion(int version)Sets the format version.voidstartObjectFrame()Starts an object frame when using a context with framing support.voidstartObjectFrame(boolean fixedsize)Starts an object frame when using a context with framing support.voidstopObjectFrame()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:
getClassloaderin interfaceIDecodingContext- Returns:
- The classloader.
-
getDecoderHandlers
public java.util.List<IDecoderHandler> getDecoderHandlers()
Returns the handlers used to decode objects.- Specified by:
getDecoderHandlersin interfaceIDecodingContext- Returns:
- The handlers.
-
getPostProcessors
public java.util.List<ITraverseProcessor> getPostProcessors()
Returns the handlers used for post-processing.- Specified by:
getPostProcessorsin interfaceIDecodingContext- Returns:
- Post-processing handlers.
-
createObjectId
public long createObjectId(java.lang.Object object)
Creates ID for an object.- Specified by:
createObjectIdin interfaceIDecodingContext- Parameters:
object- The object- Returns:
- The ID.
-
getObjectForId
public java.lang.Object getObjectForId(long id)
Gets a known object by ID.- Specified by:
getObjectForIdin 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:
setObjectForIdin 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:
getObjectIdin interfaceIDecodingContext- Parameters:
object- The object- Returns:
- The ID.
-
getUserContext
public java.lang.Object getUserContext()
Returns the user context.- Specified by:
getUserContextin interfaceIUserContextContainer- Returns:
- The user context.
-
getErrorReporter
public IErrorReporter getErrorReporter()
Gets the error reporter.- Specified by:
getErrorReporterin interfaceIDecodingContext- Returns:
- The error reporter.
-
getLastObject
public java.lang.Object getLastObject()
Returns the last object decoded.- Specified by:
getLastObjectin interfaceIDecodingContext- Returns:
- The last object decoded.
-
setLastObject
public void setLastObject(java.lang.Object lastobject)
Sets the last object decoded.- Specified by:
setLastObjectin interfaceIDecodingContext- Parameters:
lastobject- The last object decoded.
-
readBoolean
public boolean readBoolean()
Reads a boolean value from the buffer.- Specified by:
readBooleanin interfaceIDecodingContext- Returns:
- Boolean value.
-
readString
public java.lang.String readString()
Helper method for decoding a string.- Specified by:
readStringin interfaceIDecodingContext- Returns:
- String encoded at the current position.
-
readVarInt
public long readVarInt()
Helper method for decoding a variable-sized integer (VarInt).- Specified by:
readVarIntin interfaceIDecodingContext- Returns:
- The decoded value.
-
readSignedVarInt
public long readSignedVarInt()
Helper method for decoding a signed variable-sized integer (VarInt).- Specified by:
readSignedVarIntin interfaceIDecodingContext- Returns:
- The decoded value.
-
readClassname
public java.lang.String readClassname()
Helper method for decoding a class name.- Specified by:
readClassnamein 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:
getCurrentClassNamein 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:
setVersionin 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:
startObjectFramein 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:
stopObjectFramein 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:
readin 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.
-
-