コード例 #1
0
  /**
   * @param bytes
   * @return
   * @throws IOException
   * @throws Exception
   */
  private byte[] process(final byte[] bytes) throws Exception {

    final ClassReader reader = new ClassReader(new ByteArrayInputStream(bytes));
    final String name[] = ClassNameReader.getClassInfo(reader);
    final DebuggingClassWriter w = new DebuggingClassWriter(ClassWriter.COMPUTE_FRAMES);
    final ClassTransformer t = getClassTransformer(name);
    if (t != null) {
      if (verbose) {
        log("processing " + name[0]);
      }
      new TransformingClassGenerator(
              new ClassReaderGenerator(
                  new ClassReader(new ByteArrayInputStream(bytes)), attributes(), getFlags()),
              t)
          .generateClass(w);
      final ByteArrayOutputStream out = new ByteArrayOutputStream();
      out.write(w.toByteArray());
      return out.toByteArray();
    }
    return bytes;
  }
コード例 #2
0
  /**
   * @param file
   * @throws Exception
   * @throws FileNotFoundException
   * @throws IOException
   * @throws MalformedURLException
   */
  private void processClassFile(final File file)
      throws Exception, FileNotFoundException, IOException, MalformedURLException {

    final ClassReader reader = getClassReader(file);
    final String name[] = ClassNameReader.getClassInfo(reader);
    final DebuggingClassWriter w = new DebuggingClassWriter(ClassWriter.COMPUTE_FRAMES);
    final ClassTransformer t = getClassTransformer(name);
    if (t != null) {

      if (verbose) {
        log("processing " + file.toURI());
      }
      new TransformingClassGenerator(
              new ClassReaderGenerator(getClassReader(file), attributes(), getFlags()), t)
          .generateClass(w);
      final FileOutputStream fos = new FileOutputStream(file);
      try {
        fos.write(w.toByteArray());
      } finally {
        fos.close();
      }
    }
  }