MCPcopy Create free account
hub / github.com/JavaCourse00/JavaCourseCodes / findClass

Method findClass

01jvm/XlassLoader.java:32–54  ·  view source on GitHub ↗
(String name)

Source from the content-addressed store, hash-verified

30 }
31
32 @Override
33 protected Class<?> findClass(String name) throws ClassNotFoundException {
34 // 如果支持包名, 则需要进行路径转换
35 String resourcePath = name.replace(".", "/");
36 // 文件后缀
37 final String suffix = ".xlass";
38 // 获取输入流
39 InputStream inputStream = this.getClass().getClassLoader().getResourceAsStream(resourcePath + suffix);
40 try {
41 // 读取数据
42 int length = inputStream.available();
43 byte[] byteArray = new byte[length];
44 inputStream.read(byteArray);
45 // 转换
46 byte[] classBytes = decode(byteArray);
47 // 通知底层定义这个类
48 return defineClass(name, classBytes, 0, classBytes.length);
49 } catch (IOException e) {
50 throw new ClassNotFoundException(name, e);
51 } finally {
52 close(inputStream);
53 }
54 }
55
56 // 解码
57 private static byte[] decode(byte[] byteArray) {

Callers

nothing calls this directly

Calls 2

decodeMethod · 0.95
closeMethod · 0.95

Tested by

no test coverage detected