Class InjectionTools
java.lang.Object
de.aristaflow.adept2.util.injection.InjectionTools
Tool methods around the injection into deserialised objects, above all the refusal of
InjectionAware objects by streams that have no driver to complete them.-
Method Summary
Modifier and TypeMethodDescriptionstatic SerializablecheckNoInjectionAware(Serializable object) Checks that the designated object graph contains noInjectionAwareobject by writing it through a refusing stream and discarding the bytes.static ObjectGets the designated object unchanged unless it isInjectionAware, in which case the refusal of the stream applies.static byte[]toByteArray(Serializable object) Converts the designated serialisable object to a byte array,InjectionAwareobjects included.
-
Method Details
-
refuse
Gets the designated object unchanged unless it isInjectionAware, in which case the refusal of the stream applies. This is the shared verdict of the refusing streams.- Parameters:
object- The object which to refuse if it isInjectionAware.direction- The direction of the stream for the message, that is "read" or "written".- Returns:
- The designated object unchanged.
- Throws:
InjectionException- If the designated object isInjectionAware, anInjectionExceptionwill be thrown.
-
checkNoInjectionAware
Checks that the designated object graph contains noInjectionAwareobject by writing it through a refusing stream and discarding the bytes. This is for the payload of ajava.security.SignedObject, whose constructor serialises internally and can therefore not be routed through a stream of ours: the payload is serialised twice, once to check and once to sign, which the RSA signature dominates anyway.- Parameters:
object- The object graph which to check forInjectionAwareobjects.- Returns:
- The designated object.
- Throws:
IOException- If the designated object graph contains anInjectionAwareobject, anInjectionExceptionwill be thrown; if it cannot be serialised at all, anotherIOExceptionwill be thrown.
-
toByteArray
Converts the designated serialisable object to a byte array,InjectionAwareobjects included. This is the permissive counterpart ofStreamTools.toByteArray(Serializable), which refuses them.- Parameters:
object- A serialisable object to convert to a byte array.- Returns:
- A byte array representing the serialised designated object. This will never be
null. - Throws:
IOException- If there are problems when writing the designated object, anIOExceptionwill be thrown.
-