1414import java .io .File ;
1515import java .io .IOException ;
1616import java .nio .file .Files ;
17+ import java .nio .file .Paths ;
1718import java .util .List ;
1819import java .util .Map ;
1920
2021public class SaveTask extends SwingWorker <Void , Integer > {
2122
22- private File output ;
23- private PageEndPanel jpb ;
24- private JarArchive file ;
23+ private final File output ;
24+ private final PageEndPanel jpb ;
25+ private final JarArchive file ;
2526
2627 public SaveTask (JByteMod jbm , File output , JarArchive file ) {
2728 this .output = output ;
@@ -42,10 +43,10 @@ protected Void doInBackground() throws Exception {
4243 CustomClassWriter writer = new CustomClassWriter (flags );
4344 node .accept (writer );
4445 publish (50 );
45- Main .INSTANCE .getLogger ().log ("Saving.." );
46- Files .write (this .output .toPath (), writer .toByteArray ());
46+ Main .INSTANCE .getLogger ().log ("Saving.." );
47+ Files .write (new File ( this .output . toString (). replace ( ".jar" , ".class" )) .toPath (), writer .toByteArray ());
4748 publish (100 );
48- Main .INSTANCE .getLogger ().log ("Saving successful!" );
49+ Main .INSTANCE .getLogger ().log ("Saving successful!" );
4950 return null ;
5051 }
5152
@@ -78,17 +79,15 @@ protected Void doInBackground() throws Exception {
7879
7980 public void saveAsJarNew (Map <String , byte []> outBytes , String fileName ) {
8081 try {
81- ZipOutputStream out = new ZipOutputStream (new java . io . FileOutputStream (fileName ));
82+ ZipOutputStream out = new ZipOutputStream (Files . newOutputStream ( Paths . get (fileName ) ));
8283 out .setEncoding ("UTF-8" );
8384 for (String entry : outBytes .keySet ()) {
8485 out .putNextEntry (new ZipEntry (entry ));
8586 if (!entry .endsWith ("/" ) || !entry .endsWith ("\\ " ))
8687 out .write (outBytes .get (entry ));
8788 out .closeEntry ();
8889 }
89- if (out != null ) {
90- out .close ();
91- }
90+ out .close ();
9291
9392 } catch (IOException e ) {
9493 e .printStackTrace ();
0 commit comments