CtClassType(InputStream ins, ClassPool cp) throws IOException { this((String)null, cp); classfile = new ClassFile(new DataInputStream(ins)); qualifiedName = classfile.getName(); }
CtClassType(InputStream ins, ClassPool cp) throws IOException { this((String)null, cp); classfile = new ClassFile(new DataInputStream(ins)); qualifiedName = classfile.getName(); }
/** * Main method. * * @param args <code>args[0]</code> is the class file name. */ public static void main(String[] args) throws Exception { if (args.length != 1) { System.err.println("Usage: java Dump <class file name>"); return; } DataInputStream in = new DataInputStream( new FileInputStream(args[0])); ClassFile w = new ClassFile(in); PrintWriter out = new PrintWriter(System.out, true); out.println("*** constant pool ***"); w.getConstPool().print(out); out.println(); out.println("*** members ***"); ClassFilePrinter.print(w, out); } }
public ClassFile getOrCreateClassObject(final Vfs.File file) { InputStream inputStream = null; try { inputStream = file.openInputStream(); DataInputStream dis = new DataInputStream(new BufferedInputStream(inputStream)); return new ClassFile(dis); } catch (IOException e) { throw new ReflectionsException("could not create class file from " + file.getName(), e); } finally { Utils.close(inputStream); } }
CtNewClass(String name, ClassPool cp, boolean isInterface, CtClass superclass) { super(name, cp); wasChanged = true; String superName; if (isInterface || superclass == null) superName = null; else superName = superclass.getName(); classfile = new ClassFile(isInterface, name, superName); if (isInterface && superclass != null) classfile.setInterfaces(new String[] { superclass.getName() }); setModifiers(Modifier.setPublic(getModifiers())); hasConstructor = isInterface; }
/** * Main method. * * @param args <code>args[0]</code> is the class file name. */ public static void main(String[] args) throws Exception { if (args.length != 1) { System.err.println("Usage: java Dump <class file name>"); return; } DataInputStream in = new DataInputStream( new FileInputStream(args[0])); ClassFile w = new ClassFile(in); PrintWriter out = new PrintWriter(System.out, true); out.println("*** constant pool ***"); w.getConstPool().print(out); out.println(); out.println("*** members ***"); ClassFilePrinter.print(w, out); } }
public ClassFile getOfCreateClassObject(final Vfs.File file) { InputStream inputStream = null; try { inputStream = file.openInputStream(); DataInputStream dis = new DataInputStream(new BufferedInputStream(inputStream)); return new ClassFile(dis); } catch (IOException e) { throw new ReflectionsException("could not create class file from " + file.getName(), e); } finally { Utils.close(inputStream); } }
private ClassFile toClassFile(ArchiveEntry entry) { final InputStream inputStream = entry.getStreamAccess().accessInputStream(); final DataInputStream dataInputStream = new DataInputStream( inputStream ); try { return new ClassFile( dataInputStream ); } catch (IOException e) { throw new ArchiveException( "Could not build ClassFile", e ); } finally { try { dataInputStream.close(); } catch (Exception ignore) { } try { inputStream.close(); } catch (IOException ignore) { } } }
private ClassFile make(Method[] getters, Method[] setters) throws CannotCompileException { String className = targetBean.getName(); // set the name of bulk accessor. className = className + "_$$_bulkaccess_" + counter++; if ( className.startsWith( "java." ) ) { className = PACKAGE_NAME_PREFIX + className; } final ClassFile classfile = new ClassFile( false, className, BULKACESSOR_CLASS_NAME ); classfile.setAccessFlags( AccessFlag.PUBLIC ); addDefaultConstructor( classfile ); addGetter( classfile, getters ); addSetter( classfile, setters ); return classfile; }
private static void scanForMainClass(String path, Collection<String> mainClasses) { mainClasses.addAll(Scan.classpath(path).bytecodeFilter(input -> hasMainMethod(new ClassFile(new DataInputStream(input)))).getAll()); }
ClassFile classFile = new ClassFile(new DataInputStream(new ByteArrayInputStream(classfileBuffer))); List<?> attributes = classFile.getAttributes(); Iterator<?> itr = attributes.iterator();
CtNewClass(String name, ClassPool cp, boolean isInterface, CtClass superclass) { super(name, cp); wasChanged = true; String superName; if (isInterface || superclass == null) superName = null; else superName = superclass.getName(); classfile = new ClassFile(isInterface, name, superName); if (isInterface && superclass != null) classfile.setInterfaces(new String[] { superclass.getName() }); setModifiers(Modifier.setPublic(getModifiers())); hasConstructor = isInterface; }
@Override public byte[] transform(ClassLoader loader, String className, Class<?> classBeingRedefined, ProtectionDomain protectionDomain, byte[] classfileBuffer) throws IllegalClassFormatException { // Lambdas and anonymous methods in Java 8 do not have a class name defined and so no transformation should be done if (className == null || StringUtils.isBlank(getTargetedClass()) || StringUtils.isBlank(getTableName())) { return null; } byte[] classBytes = null; String convertedClassName = className.replace('/', '.'); if (convertedClassName.equalsIgnoreCase(getTargetedClass())) { try { String targetValue = getTableName(); if (LOG.isDebugEnabled()) { LOG.debug("Altering " + convertedClassName + " table name"); } ClassFile classFile = new ClassFile(new DataInputStream(new ByteArrayInputStream(classfileBuffer))); ConstPool constantPool = classFile.getConstPool(); alterTableAnnotation(classFile, targetValue, constantPool); ByteArrayOutputStream bos = new ByteArrayOutputStream(); DataOutputStream os = new DataOutputStream(bos); classFile.write(os); os.close(); classBytes = bos.toByteArray(); } catch (Exception ex) { ex.printStackTrace(); throw new IllegalClassFormatException("Unable to convert " + convertedClassName + " to a SingleTable inheritance strategy: " + ex.getMessage()); } } return classBytes; }
if (managedClassNames.contains(convertedClassName)) { try { ClassFile classFile = new ClassFile(new DataInputStream(new ByteArrayInputStream(classfileBuffer))); if (isExecuted) { return null;
private static void scanFile(Collection<String> classes, Pattern regex, Class<? extends Annotation>[] annotated, Predicate<InputStream> bytecodeFilter, String relName, File file, ZipFile zip, ZipEntry entry, AtomicInteger searched) { Log.trace("scanned file", "file", relName); if (relName.endsWith(".class")) { searched.incrementAndGet(); String clsName = Str.sub(relName, 0, -6).replace('/', '.').replace('\\', '.'); if (U.isEmpty(regex) || regex.matcher(clsName).matches()) { try { InputStream input = file != null ? new FileInputStream(file) : zip.getInputStream(entry); boolean include; if (U.isEmpty(annotated)) { include = true; } else { ClassFile classFile = new ClassFile(new DataInputStream(input)); include = isAnnotated(classFile, annotated); } if (include && bytecodeFilter != null) { include = Lmbd.eval(bytecodeFilter, input); } if (include) { classes.add(clsName); } } catch (Throwable e) { Log.debug("Error while loading class", "name", clsName, "error", e); } } } }
ClassFile classFile = new ClassFile(new DataInputStream(new ByteArrayInputStream(classfileBuffer))); boolean containsTypeLevelAnnotation = false;
private ClassFile make() throws CannotCompileException { ClassFile cf = new ClassFile(false, classname, superName); cf.setAccessFlags(AccessFlag.PUBLIC); setInterfaces(cf, interfaces, hasGetHandler ? Proxy.class : ProxyObject.class);
private ClassFile make() throws CannotCompileException { ClassFile cf = new ClassFile(false, classname, superName); cf.setAccessFlags(AccessFlag.PUBLIC); setInterfaces(cf, interfaces, hasGetHandler ? Proxy.class : ProxyObject.class);