Class InjectionTools

java.lang.Object
de.aristaflow.adept2.util.injection.InjectionTools

public class InjectionTools extends Object
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 Details

    • refuse

      public static Object refuse(Object object, String direction) throws InjectionException
      Gets the designated object unchanged unless it is InjectionAware, 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 is InjectionAware.
      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 is InjectionAware, an InjectionException will be thrown.
    • checkNoInjectionAware

      public static Serializable checkNoInjectionAware(Serializable object) throws IOException
      Checks that the designated object graph contains no InjectionAware object by writing it through a refusing stream and discarding the bytes. This is for the payload of a java.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 for InjectionAware objects.
      Returns:
      The designated object.
      Throws:
      IOException - If the designated object graph contains an InjectionAware object, an InjectionException will be thrown; if it cannot be serialised at all, another IOException will be thrown.
    • toByteArray

      public static byte[] toByteArray(Serializable object) throws IOException
      Converts the designated serialisable object to a byte array, InjectionAware objects included. This is the permissive counterpart of StreamTools.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, an IOException will be thrown.