annotations-impl/src/main/java/org/ocpsoft/rewrite/annotation/scan/ByteCodeFilter.java
@SuppressWarnings("unused")
   public boolean accept(InputStream classFileStream) throws IOException
   {

      // open a DataInputStream
      DataInputStream in = new DataInputStream(classFileStream);

      // read magic and abort if it doesn't match
      int magic = in.readInt();
      if (magic != CLASS_FILE_MAGIC)
      {
         if (log.isDebugEnabled())
         {
            log.debug("Magic not found! Not a valid class file!");
         }
         return false;
      }

      // check for at least JDK 1.5
      int minor = in.readUnsignedShort();
      int major = in.readUnsignedShort();
      if (major < 49)
      {
         // JDK 1.4 or less
         if (log.isTraceEnabled())
         {
            log.trace("Not a JDK5 class! It cannot contain annotations!");
         }
         return false;
      }

      // this values is equal to the number entries in the constants pool + 1
      int constantPoolEntries = in.readUnsignedShort() - 1;

      // loop over all entries in the constants pool
      for (int i = 0; i < constantPoolEntries; i++)
      {

         // the tag to identify the record type
         int tag = in.readUnsignedByte();

         // process record according to its type
         switch (tag)
         {

         case CONSTANT_Class:
            /*
             * CONSTANT_Class_info {
             *   u1 tag;
             *   u2 name_index;
             * }
             */
            in.readUnsignedShort();
            break;

         case CONSTANT_Fieldref:
         case CONSTANT_Methodref:
         case CONSTANT_InterfaceMethodref:
            /*
             * CONSTANT_[Fieldref|Methodref|InterfaceMethodref]_info {
             *   u1 tag;
             *   u2 class_index;
             *   u2 name_and_type_index;
             * }
             */
            in.readUnsignedShort();
            in.readUnsignedShort();
            break;

         case CONSTANT_String:
            /*
             * CONSTANT_String_info {
             *   u1 tag;
             *   u2 string_index;
             * }
             */
            in.readUnsignedShort();
            break;

         case CONSTANT_Integer:
         case CONSTANT_Float:
            /*
             * CONSTANT_[Integer|Float]_info {
             *   u1 tag;
             *   u4 bytes;
             * }
             */
            in.readInt();
            break;

         case CONSTANT_Long:
         case CONSTANT_Double:

            /*
             * CONSTANT_Long_info {
             *   u1 tag;
             *   u4 high_bytes;
             *   u4 low_bytes;
             * }
             */
            in.readLong();

            /*
             * We must increase the constant pool index because this tag
             * type takes two entries
             */
            i++;

            break;

         case CONSTANT_NameAndType:
            /*
             * CONSTANT_NameAndType_info {
             *   u1 tag;
             *   u2 name_index;
             *   u2 descriptor_index;
             * }
             */
            in.readUnsignedShort();
            in.readUnsignedShort();
            break;

         case CONSTANT_Utf8:
            /*
             * CONSTANT_Utf8_info {
             *   u1 tag;
             *   u2 length;
             *   u1 bytes[length];
             * }
             */
            String str = in.readUTF();

            // check if this string sounds interesting
            if (containsFieldDescriptor(str))
            {
               if (log.isTraceEnabled())
               {
                  log.trace("Found interesting annotation reference in constant pool: " + str);
               }
               return true;
            }
            break;
            
         case CONSTANT_MethodHandle:
           /*
            * CONSTANT_MethodHandle_info {
            *     u1 tag;
            *     u1 reference_kind;
            *     u2 reference_index;
            * }
            */
           in.readByte();
           in.readShort();
           break;
           
         case CONSTANT_MethodType:
           /*
            * CONSTANT_MethodType_info {
            *     u1 tag;
            *     u2 descriptor_index;
            * }
            */
           in.readShort();
           break;
           
         case CONSTANT_InvokeDynamic:
           /*
            * CONSTANT_InvokeDynamic_info {
            *     u1 tag;
            *     u2 bootstrap_method_attr_index;
            *     u2 name_and_type_index;
            * }
            */
           in.readShort();
           in.readShort();
           break;

         default:
            /*
             * Unknown tag! Should not happen! We will scan the class in this case.
             */
            if (log.isDebugEnabled())
            {
               log.debug("Unknown constant pool tag found: " + tag);
            }
            return true;
         }
      }

      return false;

   }
@SuppressWarnings("unused")
   public boolean accept(InputStream classFileStream) throws IOException
   {

      // open a DataInputStream
      DataInputStream in = new DataInputStream(classFileStream);

      // read magic and abort if it doesn't match
      int magic = in.readInt();
      if (magic != CLASS_FILE_MAGIC)
      {
         if (log.isDebugEnabled())
         {
            log.debug("Magic not found! Not a valid class file!");
         }
         return false;
      }

      // check for at least JDK 1.5
      int minor = in.readUnsignedShort();
      int major = in.readUnsignedShort();
      if (major < 49)
      {
         // JDK 1.4 or less
         if (log.isTraceEnabled())
         {
            log.trace("Not a JDK5 class! It cannot contain annotations!");
         }
         return false;
      }

      // this values is equal to the number entries in the constants pool + 1
      int constantPoolEntries = in.readUnsignedShort() - 1;

      // loop over all entries in the constants pool
      for (int i = 0; i < constantPoolEntries; i++)
      {

         // the tag to identify the record type
         int tag = in.readUnsignedByte();

         // process record according to its type
         switch (tag)
         {

         case CONSTANT_Class:
            /*
             * CONSTANT_Class_info {
             *   u1 tag;
             *   u2 name_index;
             * }
             */
            in.readUnsignedShort();
            break;

         case CONSTANT_Fieldref:
         case CONSTANT_Methodref:
         case CONSTANT_InterfaceMethodref:
            /*
             * CONSTANT_[Fieldref|Methodref|InterfaceMethodref]_info {
             *   u1 tag;
             *   u2 class_index;
             *   u2 name_and_type_index;
             * }
             */
            in.readUnsignedShort();
            in.readUnsignedShort();
            break;

         case CONSTANT_String:
            /*
             * CONSTANT_String_info {
             *   u1 tag;
             *   u2 string_index;
             * }
             */
            in.readUnsignedShort();
            break;

         case CONSTANT_Integer:
         case CONSTANT_Float:
            /*
             * CONSTANT_[Integer|Float]_info {
             *   u1 tag;
             *   u4 bytes;
             * }
             */
            in.readInt();
            break;

         case CONSTANT_Long:
         case CONSTANT_Double:

            /*
             * CONSTANT_Long_info {
             *   u1 tag;
             *   u4 high_bytes;
             *   u4 low_bytes;
             * }
             */
            in.readLong();

            /*
             * We must increase the constant pool index because this tag
             * type takes two entries
             */
            i++;

            break;

         case CONSTANT_NameAndType:
            /*
             * CONSTANT_NameAndType_info {
             *   u1 tag;
             *   u2 name_index;
             *   u2 descriptor_index;
             * }
             */
            in.readUnsignedShort();
            in.readUnsignedShort();
            break;

         case CONSTANT_Utf8:
            /*
             * CONSTANT_Utf8_info {
             *   u1 tag;
             *   u2 length;
             *   u1 bytes[length];
             * }
             */
            String str = in.readUTF();

            // check if this string sounds interesting
            if (containsFieldDescriptor(str))
            {
               if (log.isTraceEnabled())
               {
                  log.trace("Found interesting annotation reference in constant pool: " + str);
               }
               return true;
            }
            break;
            
         case CONSTANT_MethodHandle:
           /*
            * CONSTANT_MethodHandle_info {
            *     u1 tag;
            *     u1 reference_kind;
            *     u2 reference_index;
            * }
            */
           in.readByte();
           in.readShort();
           break;
           
         case CONSTANT_MethodType:
           /*
            * CONSTANT_MethodType_info {
            *     u1 tag;
            *     u2 descriptor_index;
            * }
            */
           in.readShort();
           break;
           
         case CONSTANT_InvokeDynamic:
           /*
            * CONSTANT_InvokeDynamic_info {
            *     u1 tag;
            *     u2 bootstrap_method_attr_index;
            *     u2 name_and_type_index;
            * }
            */
           in.readShort();
           in.readShort();
           break;

         default:
            /*
             * Unknown tag! Should not happen! We will scan the class in this case.
             */
            if (log.isDebugEnabled())
            {
               log.debug("Unknown constant pool tag found: " + tag);
            }
            return true;
         }
      }

      return false;

   }
@ SuppressWarnings ( "unused" ) public boolean accept ( InputStream classFileStream ) throws IOException { // open a DataInputStream DataInputStream in = new DataInputStream ( classFileStream ) ; // read magic and abort if it doesn't match int magic = in . readInt ( ) ; if ( magic != CLASS_FILE_MAGIC ) { if ( log . isDebugEnabled ( ) ) { log . debug ( "Magic not found! Not a valid class file!" ) ; } return false ; } // check for at least JDK 1.5 int minor = in . readUnsignedShort ( ) ; int major = in . readUnsignedShort ( ) ; if ( major < 49 ) { // JDK 1.4 or less if ( log . isTraceEnabled ( ) ) { log . trace ( "Not a JDK5 class! It cannot contain annotations!" ) ; } return false ; } // this values is equal to the number entries in the constants pool + 1 int constantPoolEntries = in . readUnsignedShort ( ) - 1 ; // loop over all entries in the constants pool for ( int i = 0 ; i < constantPoolEntries ; i ++ ) { // the tag to identify the record type int tag = in . readUnsignedByte ( ) ; // process record according to its type switch ( tag ) { case CONSTANT_Class : /*
             * CONSTANT_Class_info {
             *   u1 tag;
             *   u2 name_index;
             * }
             */ in . readUnsignedShort ( ) ; break ; case CONSTANT_Fieldref : case CONSTANT_Methodref : case CONSTANT_InterfaceMethodref : /*
             * CONSTANT_[Fieldref|Methodref|InterfaceMethodref]_info {
             *   u1 tag;
             *   u2 class_index;
             *   u2 name_and_type_index;
             * }
             */ in . readUnsignedShort ( ) ; in . readUnsignedShort ( ) ; break ; case CONSTANT_String : /*
             * CONSTANT_String_info {
             *   u1 tag;
             *   u2 string_index;
             * }
             */ in . readUnsignedShort ( ) ; break ; case CONSTANT_Integer : case CONSTANT_Float : /*
             * CONSTANT_[Integer|Float]_info {
             *   u1 tag;
             *   u4 bytes;
             * }
             */ in . readInt ( ) ; break ; case CONSTANT_Long : case CONSTANT_Double : /*
             * CONSTANT_Long_info {
             *   u1 tag;
             *   u4 high_bytes;
             *   u4 low_bytes;
             * }
             */ in . readLong ( ) ; /*
             * We must increase the constant pool index because this tag
             * type takes two entries
             */ i ++ ; break ; case CONSTANT_NameAndType : /*
             * CONSTANT_NameAndType_info {
             *   u1 tag;
             *   u2 name_index;
             *   u2 descriptor_index;
             * }
             */ in . readUnsignedShort ( ) ; in . readUnsignedShort ( ) ; break ; case CONSTANT_Utf8 : /*
             * CONSTANT_Utf8_info {
             *   u1 tag;
             *   u2 length;
             *   u1 bytes[length];
             * }
             */ String str = in . readUTF ( ) ; // check if this string sounds interesting if ( containsFieldDescriptor ( str ) ) { if ( log . isTraceEnabled ( ) ) { log . trace ( "Found interesting annotation reference in constant pool: " + str ) ; } return true ; } break ; case CONSTANT_MethodHandle : /*
            * CONSTANT_MethodHandle_info {
            *     u1 tag;
            *     u1 reference_kind;
            *     u2 reference_index;
            * }
            */ in . readByte ( ) ; in . readShort ( ) ; break ; case CONSTANT_MethodType : /*
            * CONSTANT_MethodType_info {
            *     u1 tag;
            *     u2 descriptor_index;
            * }
            */ in . readShort ( ) ; break ; case CONSTANT_InvokeDynamic : /*
            * CONSTANT_InvokeDynamic_info {
            *     u1 tag;
            *     u2 bootstrap_method_attr_index;
            *     u2 name_and_type_index;
            * }
            */ in . readShort ( ) ; in . readShort ( ) ; break ; default : /*
             * Unknown tag! Should not happen! We will scan the class in this case.
             */ if ( log . isDebugEnabled ( ) ) { log . debug ( "Unknown constant pool tag found: " + tag ) ; } return true ; } } return false ; }
<p>
Checks whether that supplied {@link InputStream} contains a Java class file that might contain references to
specific annotation types.
</p>
<p>
The caller of this method is responsible to close the supplied {@link InputStream}. This method won't do it!
</p>

@param classFileStream The stream to read the class file from.
@return <code>true</code> for files that contain at least one reference to one of the "interesting" annotations
@throws IOException for any kind of IO problem
<p > Checks whether that supplied { @link InputStream } contains a Java class file that might contain references to specific annotation types . < / p > <p > The caller of this method is responsible to close the supplied { @link InputStream } . This method won t do it! < / p >