File tree Expand file tree Collapse file tree
src/main/java/club/shengsheng Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11package 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 **/
107public 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}
You can’t perform that action at this time.
0 commit comments