public static byte [ ] readClass ( String className ) throws IOException { // convert to a resource className = ClassUtils . classNameToResource ( className ) ; byte [ ] b = new byte [ 2500 ] ; // I'm assuming that I'm reading class that are not too big int length ; try ( InputStream in = ClassDefinitionUtils . class . getClassLoader ( ) . getResourceAsStream ( className ) ) { length = in . read ( b ) ; } if ( length >= 2500 ) { throw new IllegalArgumentException ( "The class is longer that 2500 bytes which is currently unsupported" ) ; } byte [ ] copy = new byte [ length ] ; System . arraycopy ( b , 0 , copy , 0 , length ) ; return copy ; }
Read the bytes of a class from the classpath