Interface ClassTransformer

  • All Known Implementing Classes:
    JLIClassTransformer

    public interface ClassTransformer
    A class file transformer which operates on byte buffers.
    • Field Detail

      • IDENTITY

        static final ClassTransformer IDENTITY
        The identity transformation, which does not modify the class bytes at all.
    • Method Detail

      • transform

        java.nio.ByteBuffer transform​(java.lang.ClassLoader loader,
                                      java.lang.String className,
                                      java.security.ProtectionDomain protectionDomain,
                                      java.nio.ByteBuffer classBytes)
                               throws java.lang.IllegalArgumentException
        Transform the bytes of a class. The position and limit of both the passed-in and returned buffers must mark the start and end of the class bytes.
        Parameters:
        loader - the class loader of the class being transformed
        className - the internal name of the class being transformed (not null)
        protectionDomain - the protection domain of the class, if any
        classBytes - the class bytes being transformed (not null; may be a direct or heap buffer)
        Returns:
        the transformation result (may be a direct or heap buffer)
        Throws:
        java.lang.IllegalArgumentException - if the class could not be transformed for some reason
      • andThen

        default ClassTransformer andThen​(ClassTransformer other)
        Get a new transformer which applies this transformation followed by another transformation.
        Parameters:
        other - the other transformation (must not be null)
        Returns:
        the new transformer (not null)
      • allOf

        static ClassTransformer allOf​(java.util.Collection<? extends ClassTransformer> transformers)
        Get a new transformer which applies all the transformations in the given collection. The collection should either be immutable or safe for concurrent iteration. A synchronized collection is insufficiently thread-safe.
        Parameters:
        transformers - the transformer collection (must not be null)
        Returns:
        the new transformer (not null)