Example #1
0
  /**
   * Creates a new class (or interface) from the given class file. If there already exists a class
   * with the same name, the new class overwrites that previous class.
   *
   * <p>This method is used for creating a <code>CtClass</code> object directly from a class file.
   * The qualified class name is obtained from the class file; you do not have to explicitly give
   * the name.
   *
   * @param classfile class file.
   * @param ifNotFrozen throws a RuntimeException if this parameter is true and there is a frozen
   *     class with the same name.
   * @see javassist.ByteArrayClassPath
   */
  public CtClass makeClass(InputStream classfile, boolean ifNotFrozen)
      throws IOException, RuntimeException {
    compress();
    classfile = new BufferedInputStream(classfile);
    CtClass clazz = new CtClassType(classfile, this);
    clazz.checkModify();
    String classname = clazz.getName();
    if (ifNotFrozen) checkNotFrozen(classname);

    cacheCtClass(classname, clazz, true);
    return clazz;
  }
Example #2
0
 /**
  * Creates a new class (or interface) from the given class file. If there already exists a class
  * with the same name, this method returns the existing class; a new class is never created from
  * the given class file.
  *
  * <p>This method is used for creating a <code>CtClass</code> object directly from a class file.
  * The qualified class name is obtained from the class file; you do not have to explicitly give
  * the name.
  *
  * @param classfile the class file.
  * @see #makeClass(InputStream)
  * @see javassist.ByteArrayClassPath
  * @since 3.9
  */
 public CtClass makeClassIfNew(InputStream classfile) throws IOException, RuntimeException {
   compress();
   classfile = new BufferedInputStream(classfile);
   CtClass clazz = new CtClassType(classfile, this);
   clazz.checkModify();
   String classname = clazz.getName();
   CtClass found = checkNotExists(classname);
   if (found != null) return found;
   else {
     cacheCtClass(classname, clazz, true);
     return clazz;
   }
 }