本文整理匯總了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();
}
}