Skip to content

Commit 471ae44

Browse files
committed
saveAsJar Should Throw Exceptions
1 parent cf92749 commit 471ae44

File tree

5 files changed

+64
-26
lines changed

5 files changed

+64
-26
lines changed

src/main/java/the/bytecode/club/bytecodeviewer/GlobalHotKeys.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import javax.swing.*;
2828
import java.awt.event.KeyEvent;
2929
import java.io.File;
30+
import java.io.IOException;
3031

3132
/**
3233
* Whenever a key is pressed on the swing UI it should get logged here
@@ -121,8 +122,18 @@ else if ((e.getKeyCode() == KeyEvent.VK_S) && ((e.getModifiersEx() & KeyEvent.CT
121122
BytecodeViewer.updateBusyStatus(true);
122123
Thread jarExport = new Thread(() ->
123124
{
124-
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), file.getAbsolutePath());
125-
BytecodeViewer.updateBusyStatus(false);
125+
try
126+
{
127+
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), file.getAbsolutePath());
128+
}
129+
catch (IOException ex)
130+
{
131+
BytecodeViewer.handleException(ex);
132+
}
133+
finally
134+
{
135+
BytecodeViewer.updateBusyStatus(false);
136+
}
126137
}, "Jar Export");
127138
jarExport.start();
128139
}

src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/APKExport.java

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131

3232
import javax.swing.*;
3333
import java.io.File;
34+
import java.io.IOException;
3435
import java.util.ArrayList;
3536
import java.util.Collection;
3637
import java.util.List;
@@ -109,17 +110,26 @@ public void promptForExport()
109110

110111
Thread saveThread = new Thread(() ->
111112
{
112-
BytecodeViewer.updateBusyStatus(true);
113-
final String input = TEMP_DIRECTORY + FS + MiscUtils.getRandomizedName() + ".jar";
114-
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input);
113+
try
114+
{
115+
BytecodeViewer.updateBusyStatus(true);
116+
final String input = TEMP_DIRECTORY + FS + MiscUtils.getRandomizedName() + ".jar";
117+
118+
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input);
115119

116-
Thread buildAPKThread = new Thread(() ->
120+
Thread buildAPKThread = new Thread(() ->
121+
{
122+
APKTool.buildAPK(new File(input), file, finalContainer);
123+
BytecodeViewer.updateBusyStatus(false);
124+
}, "Process APK");
125+
126+
buildAPKThread.start();
127+
}
128+
catch (IOException ex)
117129
{
118-
APKTool.buildAPK(new File(input), file, finalContainer);
119130
BytecodeViewer.updateBusyStatus(false);
120-
}, "Process APK");
121-
122-
buildAPKThread.start();
131+
BytecodeViewer.handleException(ex);
132+
}
123133
}, "Jar Export");
124134

125135
saveThread.start();

src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/DexExport.java

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
import javax.swing.*;
3131
import java.io.File;
32+
import java.io.IOException;
3233

3334
import static the.bytecode.club.bytecodeviewer.Constants.FS;
3435
import static the.bytecode.club.bytecodeviewer.Constants.TEMP_DIRECTORY;
@@ -73,18 +74,27 @@ public void promptForExport()
7374

7475
Thread saveAsJar = new Thread(() ->
7576
{
76-
BytecodeViewer.updateBusyStatus(true);
77-
final String input = TEMP_DIRECTORY + FS + MiscUtils.getRandomizedName() + ".jar";
78-
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input);
79-
80-
Thread saveAsDex = new Thread(() ->
77+
try
8178
{
82-
Dex2Jar.saveAsDex(new File(input), outputPath);
79+
BytecodeViewer.updateBusyStatus(true);
80+
final String input = TEMP_DIRECTORY + FS + MiscUtils.getRandomizedName() + ".jar";
81+
82+
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), input);
8383

84-
BytecodeViewer.updateBusyStatus(false);
85-
}, "Process DEX");
84+
Thread saveAsDex = new Thread(() ->
85+
{
86+
Dex2Jar.saveAsDex(new File(input), outputPath);
87+
88+
BytecodeViewer.updateBusyStatus(false);
89+
}, "Process DEX");
8690

87-
saveAsDex.start();
91+
saveAsDex.start();
92+
}
93+
catch (IOException ex)
94+
{
95+
BytecodeViewer.updateBusyStatus(false);
96+
BytecodeViewer.handleException(ex);
97+
}
8898
}, "Jar Export");
8999

90100
saveAsJar.start();

src/main/java/the/bytecode/club/bytecodeviewer/resources/exporting/impl/ZipExport.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import javax.swing.*;
3030
import java.io.File;
31+
import java.io.IOException;
3132

3233
/**
3334
* @author Konloch
@@ -65,8 +66,18 @@ public void promptForExport()
6566

6667
Thread saveThread = new Thread(() ->
6768
{
68-
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), file.getAbsolutePath());
69-
BytecodeViewer.updateBusyStatus(false);
69+
try
70+
{
71+
JarUtils.saveAsJar(BytecodeViewer.getLoadedClasses(), file.getAbsolutePath());
72+
}
73+
catch (IOException ex)
74+
{
75+
BytecodeViewer.handleException(ex);
76+
}
77+
finally
78+
{
79+
BytecodeViewer.updateBusyStatus(false);
80+
}
7081
}, "Jar Export");
7182

7283
saveThread.start();

src/main/java/the/bytecode/club/bytecodeviewer/util/JarUtils.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ public static void saveAsJarClassesOnlyToDir(List<ClassNode> nodeList, String di
405405
* @param nodeList The loaded ClassNodes
406406
* @param path the exact jar output path
407407
*/
408-
public static void saveAsJar(List<ClassNode> nodeList, String path)
408+
public static void saveAsJar(List<ClassNode> nodeList, String path) throws IOException
409409
{
410410
try (FileOutputStream fos = new FileOutputStream(path);
411411
JarOutputStream out = new JarOutputStream(fos))
@@ -448,9 +448,5 @@ public static void saveAsJar(List<ClassNode> nodeList, String path)
448448

449449
fileCollisionPrevention .clear();
450450
}
451-
catch (IOException e)
452-
{
453-
BytecodeViewer.handleException(e);
454-
}
455451
}
456452
}

0 commit comments

Comments
 (0)