You could try something like this:

public static byte[] getClassBytes(Class clazz) throws IOException
{
String name = clazz.getName().replace('.', '/') + ".class";
InputStream...