Skip to content

Commit e1eaa0e

Browse files
committed
算法 等面试之前学得
1 parent 1ec13a9 commit e1eaa0e

150 files changed

Lines changed: 4555 additions & 1023 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎.idea/JavaZone.iml‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/encodings.xml‎

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/libraries/com_google_code_gson_gson_2_8_6.xml‎

Lines changed: 10 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/libraries/com_squareup_retrofit2_converter_gson_2_0_2.xml‎

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/libraries/com_squareup_retrofit2_retrofit_2_2_0.xml‎

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.idea/libraries/javassist_javassist_3_12_1_GA.xml‎

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
println new Date()."toString"()
2+
println "new Date()"."toString"()

‎HttpTest2/test2.iml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,6 @@
1111
<orderEntry type="sourceFolder" forTests="false" />
1212
<orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.10.0" level="project" />
1313
<orderEntry type="library" name="Maven: com.squareup.okio:okio:1.14.0" level="project" />
14+
<orderEntry type="library" name="groovy-3.0.4" level="application" />
1415
</component>
1516
</module>

‎HttpTest3/pom.xml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,6 @@
9393
<version>${kotlin.version}</version>
9494
<scope>test</scope>
9595
</dependency>
96+
9697
</dependencies>
9798
</project>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package hook.classloader;
2+
3+
import java.io.*;
4+
import java.util.HashSet;
5+
6+
class CustomCL extends ClassLoader {
7+
8+
private String basedir; // 需要该类加载器直接加载的类文件的基目录
9+
private HashSet dynaclazns; // 需要由该类加载器直接加载的类名
10+
11+
public CustomCL(String basedir, String[] clazns) throws IOException {
12+
super(null); // 指定父类加载器为 null
13+
this.basedir = basedir;
14+
dynaclazns = new HashSet();
15+
loadClassByMe(clazns);
16+
}
17+
18+
private void loadClassByMe(String[] clazns) throws IOException {
19+
for (int i = 0; i < clazns.length; i++) {
20+
loadDirectly(clazns[i]);
21+
dynaclazns.add(clazns[i]);
22+
}
23+
}
24+
25+
private Class loadDirectly(String name) throws IOException {
26+
Class cls = null;
27+
StringBuffer sb = new StringBuffer(basedir);
28+
String classname = name.replace('.', File.separatorChar) + ".class";
29+
sb.append(File.separator + classname);
30+
File classF = new File(sb.toString());
31+
cls = instantiateClass(name, new FileInputStream(classF), classF.length());
32+
return cls;
33+
}
34+
35+
private Class instantiateClass(String name, InputStream fin, long len) throws IOException {
36+
byte[] raw = new byte[(int) len];
37+
fin.read(raw);
38+
fin.close();
39+
return defineClass(name, raw, 0, raw.length);
40+
}
41+
42+
protected Class loadClass(String name, boolean resolve) throws ClassNotFoundException {
43+
Class cls = null;
44+
cls = findLoadedClass(name);
45+
if (!this.dynaclazns.contains(name) && cls == null)
46+
cls = getSystemClassLoader().loadClass(name);
47+
if (cls == null)
48+
throw new ClassNotFoundException(name);
49+
if (resolve)
50+
resolveClass(cls);
51+
return cls;
52+
}
53+
54+
}

0 commit comments

Comments
 (0)