本文整理汇总了Java中javassist.bytecode.ClassFile.write方法的典型用法代码示例。如果您正苦于以下问题:Java ClassFile.write方法的具体用法?Java ClassFile.write怎么用?Java ClassFile.write使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javassist.bytecode.ClassFile
的用法示例。
在下文中一共展示了ClassFile.write方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeFile0
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
private static void writeFile0(ClassFile cf, String directoryName)
throws CannotCompileException, IOException {
String classname = cf.getName();
String filename = directoryName + File.separatorChar
+ classname.replace('.', File.separatorChar) + ".class";
int pos = filename.lastIndexOf(File.separatorChar);
if (pos > 0) {
String dir = filename.substring(0, pos);
if (!dir.equals("."))
new File(dir).mkdirs();
}
DataOutputStream out = new DataOutputStream(new BufferedOutputStream(
new FileOutputStream(filename)));
try {
cf.write(out);
}
catch (IOException e) {
throw e;
}
finally {
out.close();
}
}
示例2: transform
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
/**
* Transform the class contained in the given file, writing the result back to the same file.
*
* @param file The file containing the class to be transformed
*
* @throws Exception Indicates a problem performing the transformation
*/
public void transform(File file) throws Exception {
final DataInputStream in = new DataInputStream( new FileInputStream( file ) );
final ClassFile classfile = new ClassFile( in );
transform( classfile );
final DataOutputStream out = new DataOutputStream( new FileOutputStream( file ) );
try {
classfile.write( out );
}
finally {
out.close();
}
}
示例3: toBytecode
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
private static byte[] toBytecode(ClassFile cf) throws IOException {
ByteArrayOutputStream barray = new ByteArrayOutputStream();
DataOutputStream out = new DataOutputStream(barray);
try {
cf.write(out);
}
finally {
out.close();
}
return barray.toByteArray();
}
示例4: dumpClassFile
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
private void dumpClassFile(ClassFile cf) throws IOException {
DataOutputStream dump = makeFileOutput(debugDump);
try {
cf.write(dump);
}
finally {
dump.close();
}
}
示例5: transform
import javassist.bytecode.ClassFile; //导入方法依赖的package包/类
public void transform(File file) throws Exception {
DataInputStream in = new DataInputStream(new FileInputStream(file));
ClassFile classfile = new ClassFile(in);
transform(classfile);
DataOutputStream out = new DataOutputStream(new FileOutputStream(file));
try {
classfile.write(out);
} finally {
out.close();
}
}