Don't append new class files, overwrite them

This commit is contained in:
Victorious3 2023-01-31 14:21:16 +01:00
parent a7720fbf20
commit baec9999db
2 changed files with 2 additions and 2 deletions

View File

@ -909,7 +909,7 @@ public class JavaTXCompiler {
// "/testBytecode/generatedBC/" +name+".class")); // "/testBytecode/generatedBC/" +name+".class"));
File outputFile = new File(path, name.getClassName() + ".class"); File outputFile = new File(path, name.getClassName() + ".class");
outputFile.getAbsoluteFile().getParentFile().mkdirs(); outputFile.getAbsoluteFile().getParentFile().mkdirs();
output = new FileOutputStream(outputFile, false); output = new FileOutputStream(outputFile);
output.write(bytecode); output.write(bytecode);
output.close(); output.close();
System.out.println(name + ".class file generated"); System.out.println(name + ".class file generated");

View File

@ -31,7 +31,7 @@ public class TestCodegen {
private static void writeClassFile(String name, byte[] code) throws IOException { private static void writeClassFile(String name, byte[] code) throws IOException {
var path = Path.of(System.getProperty("user.dir"), "src/test/resources/target/"); var path = Path.of(System.getProperty("user.dir"), "src/test/resources/target/");
Files.createDirectories(path); Files.createDirectories(path);
Files.write(path.resolve(name + ".class"), code, StandardOpenOption.CREATE); Files.write(path.resolve(name + ".class"), code, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
} }
public static Class<?> generateClass(TargetClass clazz, IByteArrayClassLoader classLoader) throws IOException { public static Class<?> generateClass(TargetClass clazz, IByteArrayClassLoader classLoader) throws IOException {