Package org.infinispan.commons.marshall
Class AbstractMarshaller
- java.lang.Object
-
- org.infinispan.commons.marshall.AbstractMarshaller
-
- All Implemented Interfaces:
Marshaller
- Direct Known Subclasses:
AbstractJBossMarshaller,IdentityMarshaller,JavaSerializationMarshaller,ProtoStreamMarshaller,StringMarshaller
public abstract class AbstractMarshaller extends java.lang.Object implements Marshaller
Abstract Marshaller implementation containing shared implementations.- Since:
- 4.1
- Author:
- Galder ZamarreƱo
-
-
Field Summary
Fields Modifier and Type Field Description protected MarshallableTypeHintsmarshallableTypeHints
-
Constructor Summary
Constructors Constructor Description AbstractMarshaller()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description BufferSizePredictorgetBufferSizePredictor(java.lang.Object o)Returns a marshalled payload size predictor for a particular type.java.lang.ObjectobjectFromByteBuffer(byte[] buf)Unmarshalls an object from a byte array.java.lang.ObjectobjectFromInputStream(java.io.InputStream inputStream)This method implementsStreamingMarshaller.objectFromInputStream(java.io.InputStream), but its implementation has been moved here rather that keeping under a class that implements StreamingMarshaller in order to avoid code duplication.ByteBufferobjectToBuffer(java.lang.Object obj)A method that returns an instance ofByteBuffer, which allows direct access to the byte array with minimal array copyingprotected abstract ByteBufferobjectToBuffer(java.lang.Object o, int estimatedSize)This is a convenience method for converting an object into aByteBufferwhich takes an estimated size as parameter.byte[]objectToByteBuffer(java.lang.Object o)Marshalls an object to a byte array.byte[]objectToByteBuffer(java.lang.Object obj, int estimatedSize)Marshalls an object to a byte array.-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.infinispan.commons.marshall.Marshaller
initialize, isMarshallable, mediaType, objectFromByteBuffer, start, stop
-
-
-
-
Field Detail
-
marshallableTypeHints
protected final MarshallableTypeHints marshallableTypeHints
-
-
Method Detail
-
getBufferSizePredictor
public BufferSizePredictor getBufferSizePredictor(java.lang.Object o)
Description copied from interface:MarshallerReturns a marshalled payload size predictor for a particular type. Accurate prediction of a type's serialized payload size helps avoid unnecessary copying and speeds up application performance.- Specified by:
getBufferSizePredictorin interfaceMarshaller- Parameters:
o- Object for which serialized predictor will be returned- Returns:
- an instance of
BufferSizePredictor
-
objectToBuffer
protected abstract ByteBuffer objectToBuffer(java.lang.Object o, int estimatedSize) throws java.io.IOException, java.lang.InterruptedException
This is a convenience method for converting an object into aByteBufferwhich takes an estimated size as parameter. AByteBufferallows direct access to the byte array with minimal array copying- Parameters:
o- object to marshallestimatedSize- an estimate of how large the resulting byte array may be- Throws:
java.io.IOExceptionjava.lang.InterruptedException
-
objectToBuffer
public ByteBuffer objectToBuffer(java.lang.Object obj) throws java.io.IOException, java.lang.InterruptedException
Description copied from interface:MarshallerA method that returns an instance ofByteBuffer, which allows direct access to the byte array with minimal array copying- Specified by:
objectToBufferin interfaceMarshaller- Parameters:
obj- object to marshall- Throws:
java.io.IOException- if marshalling cannot complete due to some I/O errorjava.lang.InterruptedException- if the marshalling process was interrupted. Clients should take this as a sign that the marshaller is no longer available, maybe due to shutdown, and so no more marshalling should be attempted.
-
objectToByteBuffer
public byte[] objectToByteBuffer(java.lang.Object o) throws java.io.IOException, java.lang.InterruptedExceptionDescription copied from interface:MarshallerMarshalls an object to a byte array.- Specified by:
objectToByteBufferin interfaceMarshaller- Parameters:
o- object to convert to a byte array. Must not be null.- Returns:
- a byte array
- Throws:
java.io.IOException- if marshalling cannot complete due to some I/O errorjava.lang.InterruptedException- if the marshalling process was interrupted. Clients should take this as a sign that the marshaller is no longer available, maybe due to shutdown, and so no more marshalling should be attempted.
-
objectToByteBuffer
public byte[] objectToByteBuffer(java.lang.Object obj, int estimatedSize) throws java.io.IOException, java.lang.InterruptedExceptionDescription copied from interface:MarshallerMarshalls an object to a byte array. The estimatedSize parameter is a hint that can be passed in to allow for efficient sizing of the byte array before attempting to marshall the object. The more accurate this estimate is, the less likely byte[]s will need to be resized to hold the byte stream generated by marshalling the object.- Specified by:
objectToByteBufferin interfaceMarshaller- Parameters:
obj- object to convert to a byte array. Must not be null.estimatedSize- an estimate of how large the resulting byte array may be- Returns:
- a byte array with the marshalled form of the object
- Throws:
java.io.IOException- if marshalling cannot complete due to some I/O errorjava.lang.InterruptedException- if the marshalling was interrupted. Clients should take this as a sign that the marshaller is no longer available, maybe due to shutdown, and so no more unmarshalling should be attempted.
-
objectFromByteBuffer
public java.lang.Object objectFromByteBuffer(byte[] buf) throws java.io.IOException, java.lang.ClassNotFoundExceptionDescription copied from interface:MarshallerUnmarshalls an object from a byte array.- Specified by:
objectFromByteBufferin interfaceMarshaller- Parameters:
buf- byte array containing the binary representation of an object. Must not be null.- Returns:
- an object
- Throws:
java.io.IOException- if unmarshalling cannot complete due to some I/O errorjava.lang.ClassNotFoundException- if the class of the object trying to unmarshall is unknown
-
objectFromInputStream
public java.lang.Object objectFromInputStream(java.io.InputStream inputStream) throws java.io.IOException, java.lang.ClassNotFoundExceptionThis method implementsStreamingMarshaller.objectFromInputStream(java.io.InputStream), but its implementation has been moved here rather that keeping under a class that implements StreamingMarshaller in order to avoid code duplication.- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
-