Class ByteCodeFilter

java.lang.Object
org.ocpsoft.rewrite.annotation.scan.ByteCodeFilter

public class ByteCodeFilter extends Object

This class reads Java class files and checks whether they contain references to specific annotations. This allows to check classes for the presence of annotations before instantiating them.

The filter is inspired by the ClassByteCodeAnnotationFilter of Apache MyFaces 2.0. Many thanks go out to Leonardo Uribe for his great work on this class.

Author:
Christian Kaltepoth
  • Constructor Details

    • ByteCodeFilter

      public ByteCodeFilter(Set<Class<? extends Annotation>> types)
      The filter must be initialized with a list of types to look for when scanning the class files. If a class files contains a reference to one of these types, the filter will accept the class.
      Parameters:
      types - A Set of types to look for
  • Method Details

    • accept

      public boolean accept(InputStream classFileStream) throws IOException

      Checks whether that supplied InputStream contains a Java class file that might contain references to specific annotation types.

      The caller of this method is responsible to close the supplied InputStream. This method won't do it!

      Parameters:
      classFileStream - The stream to read the class file from.
      Returns:
      true for files that contain at least one reference to one of the "interesting" annotations
      Throws:
      IOException - for any kind of IO problem
    • toString

      public String toString()
      Overrides:
      toString in class Object