Skip to content

Commit

Permalink
some more clear renaming
Browse files Browse the repository at this point in the history
  • Loading branch information
AnAwesomGuy committed Sep 11, 2024
1 parent 62824ac commit 5c20016
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 26 deletions.
24 changes: 12 additions & 12 deletions src/java5/java/net/anawesomguy/clsdump/Dumper.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,13 @@ public Dumper(boolean debug) {
this.debug = debug;
}

private static void rm(File f) {
if (f.isDirectory())
private static void rm(File file) {
if (file.isDirectory())
//noinspection DataFlowIssue
for (File c : f.listFiles())
rm(c);
if (!f.delete())
throw new RuntimeException("Failed to delete: ".concat(f.getPath()));
for (File f : file.listFiles())
rm(f);
if (!file.delete())
throw new RuntimeException("Failed to delete: ".concat(file.getPath()));
}

public static void premain(String args, Instrumentation inst) {
Expand All @@ -45,10 +45,10 @@ public static void premain(String args, Instrumentation inst) {
InputStream in = c.getResourceAsStream(cls.substring(name.lastIndexOf('/') + 1));
if (in != null) {
try {
File f = new File(DIR, cls);
File file = new File(DIR, cls);
//noinspection ResultOfMethodCallIgnored ???????? (what)
f.getParentFile().mkdirs();
FileOutputStream out = new FileOutputStream(f);
file.getParentFile().mkdirs();
FileOutputStream out = new FileOutputStream(file);
try {
byte[] buf = new byte[8192];
for (int i; (i = in.read(buf)) != -1;)
Expand All @@ -73,10 +73,10 @@ public static void premain(String args, Instrumentation inst) {

public byte[] transform(ClassLoader classLoader, String name, Class<?> clazz, ProtectionDomain protectionDomain, byte[] buf) {
try {
File f = new File(DIR, name.concat(".class"));
File file = new File(DIR, name.concat(".class"));
//noinspection ResultOfMethodCallIgnored ???????? (what)
f.getParentFile().mkdirs();
FileOutputStream out = new FileOutputStream(f);
file.getParentFile().mkdirs();
FileOutputStream out = new FileOutputStream(file);
try {
out.write(buf);
} finally {
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/net/anawesomguy/clsdump/Dumper.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,19 @@ public final class Dumper implements ClassFileTransformer {
static {
if (Files.exists(DIR))
try {
try (Stream<Path> s = Files.walk(DIR)) {
s.sorted(Comparator.reverseOrder()).forEach(Dumper::rm);
try (Stream<Path> walk = Files.walk(DIR)) {
walk.sorted(Comparator.reverseOrder()).forEach(Dumper::rm);
}
} catch (IOException e) {
throw new RuntimeException(e);
}
}

private static void rm(Path p) {
private static void rm(Path path) {
try {
Files.delete(p);
Files.delete(path);
} catch (IOException e) {
throw new RuntimeException(p.toString(), e);
throw new RuntimeException(path.toString(), e);
}
}

Expand All @@ -46,16 +46,16 @@ public static void premain(String args, Instrumentation inst) {
inst.addTransformer(new Dumper(debug));

//already loaded classes
for (Class<?> c : inst.getAllLoadedClasses()) {
if (c.isArray())
for (Class<?> cls : inst.getAllLoadedClasses()) {
if (cls.isArray())
continue;
String name = c.getName().replace('.', '/');
String name = cls.getName().replace('.', '/');
try {
String cls = name + ".class";
InputStream in = c.getResourceAsStream(cls.substring(name.lastIndexOf('/') + 1));
String clsName = name + ".class";
InputStream in = cls.getResourceAsStream(clsName.substring(name.lastIndexOf('/') + 1));
if (in != null) {
try {
Path path = DIR.resolve(cls);
Path path = DIR.resolve(clsName);
Files.createDirectories(path.getParent());
Files.copy(in, path, StandardCopyOption.REPLACE_EXISTING);
} finally {
Expand All @@ -75,9 +75,9 @@ public static void premain(String args, Instrumentation inst) {

public byte[] transform(ClassLoader classLoader, String name, Class<?> clazz, ProtectionDomain protectionDomain, byte[] buf) {
try {
Path p = DIR.resolve(name + ".class");
Files.createDirectories(p.getParent());
Files.write(p, buf);
Path path = DIR.resolve(name + ".class");
Files.createDirectories(path.getParent());
Files.write(path, buf);
if (debug)
System.out.println("Dumped class " + name);
} catch (Exception e) {
Expand Down

0 comments on commit 5c20016

Please sign in to comment.