Skip to content

Commit 5746ff5

Browse files
Revert "feat: submit homework implementation of custom class loader (#14)"
This reverts commit bb77e80.
1 parent bb77e80 commit 5746ff5

1 file changed

Lines changed: 0 additions & 41 deletions

File tree

Lines changed: 0 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,9 @@
11
package club.shengsheng;
22

3-
import java.io.File;
4-
import java.io.IOException;
5-
import java.nio.file.Files;
63

74
/**
85
* @author gongxuanzhangmelt@gmail.com
96
**/
107
public class MyClassLoader extends ClassLoader {
11-
//
12-
public static void main(String[] args) {
13-
System.out.println("hello");
14-
}
15-
16-
@Override
17-
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {
18-
19-
synchronized (getClassLoadingLock(name)) {
20-
Class<?> loadClass = findLoadedClass(name);
21-
if (loadClass != null) {
22-
return loadClass;
23-
}
24-
if (name.startsWith("tech")) {
25-
loadClass = findClass(name);
26-
} else {
27-
loadClass = getParent().loadClass(name);
28-
}
29-
if (resolve) {
30-
resolveClass(loadClass);
31-
}
32-
return loadClass;
33-
}
34-
}
35-
36-
@Override
37-
protected Class<?> findClass(String name) throws ClassNotFoundException {
38-
try {
39-
File file = new File(System.getProperty("user.dir") + File.separatorChar + "加密.class");
40-
byte[] bytes = Files.readAllBytes(file.toPath());
41-
for (int i = 0; i < bytes.length; i++) {
42-
bytes[i] = (byte) (bytes[i] - 1);
43-
}
44-
return defineClass(name, bytes, 0, bytes.length);
45-
} catch (IOException e) {
46-
throw new ClassNotFoundException(name);
47-
}
48-
}
498

509
}

0 commit comments

Comments
 (0)