From d54d7bc69b45c3ba18b7831a534ef77ae2873cae Mon Sep 17 00:00:00 2001 From: xBrownieCodez <72617433+xBrownieCodezV2@users.noreply.github.com> Date: Fri, 12 Jul 2024 17:17:32 +0200 Subject: [PATCH] save single file as .class --- .../me/grax/jbytemod/utils/task/SaveTask.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/src/main/java/me/grax/jbytemod/utils/task/SaveTask.java b/src/main/java/me/grax/jbytemod/utils/task/SaveTask.java index ea0bea6..42beed6 100644 --- a/src/main/java/me/grax/jbytemod/utils/task/SaveTask.java +++ b/src/main/java/me/grax/jbytemod/utils/task/SaveTask.java @@ -14,14 +14,15 @@ import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.nio.file.Paths; import java.util.List; import java.util.Map; public class SaveTask extends SwingWorker { - private File output; - private PageEndPanel jpb; - private JarArchive file; + private final File output; + private final PageEndPanel jpb; + private final JarArchive file; public SaveTask(JByteMod jbm, File output, JarArchive file) { this.output = output; @@ -42,10 +43,10 @@ protected Void doInBackground() throws Exception { CustomClassWriter writer = new CustomClassWriter(flags); node.accept(writer); publish(50); - Main.INSTANCE.getLogger().log("Saving.."); - Files.write(this.output.toPath(), writer.toByteArray()); + Main.INSTANCE.getLogger().log("Saving.."); + Files.write(new File(this.output.toString().replace(".jar", ".class")).toPath(), writer.toByteArray()); publish(100); - Main.INSTANCE.getLogger().log("Saving successful!"); + Main.INSTANCE.getLogger().log("Saving successful!"); return null; } @@ -78,7 +79,7 @@ protected Void doInBackground() throws Exception { public void saveAsJarNew(Map outBytes, String fileName) { try { - ZipOutputStream out = new ZipOutputStream(new java.io.FileOutputStream(fileName)); + ZipOutputStream out = new ZipOutputStream(Files.newOutputStream(Paths.get(fileName))); out.setEncoding("UTF-8"); for (String entry : outBytes.keySet()) { out.putNextEntry(new ZipEntry(entry)); @@ -86,9 +87,7 @@ public void saveAsJarNew(Map outBytes, String fileName) { out.write(outBytes.get(entry)); out.closeEntry(); } - if (out != null) { - out.close(); - } + out.close(); } catch (IOException e) { e.printStackTrace();