Review - II Kevin Gilmore
This commit is contained in:
parent
74ebfa24ef
commit
c1a9c42194
@ -1,11 +0,0 @@
|
|||||||
package com.baeldung.loadedclasslisting.customLoader;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
public class ClassLoaderInfo {
|
|
||||||
|
|
||||||
public void printClassLoaders() throws ClassNotFoundException {
|
|
||||||
System.out.println("Classloader of this class:" + ClassLoaderInfo.class.getClassLoader());
|
|
||||||
System.out.println("Classloader of ArrayList:" + ArrayList.class.getClassLoader());
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,32 +0,0 @@
|
|||||||
package com.baeldung.loadedclasslisting.customLoader;
|
|
||||||
|
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
public class CustomClassLoader extends ClassLoader {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Class<?> findClass(String name) throws ClassNotFoundException {
|
|
||||||
byte[] b = loadClassFromFile(name);
|
|
||||||
return defineClass(name, b, 0, b.length);
|
|
||||||
}
|
|
||||||
|
|
||||||
private byte[] loadClassFromFile(String fileName) {
|
|
||||||
InputStream inputStream = getClass().getClassLoader()
|
|
||||||
.getResourceAsStream(fileName.replace('.', File.separatorChar) + ".class");
|
|
||||||
byte[] buffer;
|
|
||||||
ByteArrayOutputStream byteStream = new ByteArrayOutputStream();
|
|
||||||
int nextValue = 0;
|
|
||||||
try {
|
|
||||||
while ((nextValue = inputStream.read()) != -1) {
|
|
||||||
byteStream.write(nextValue);
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
buffer = byteStream.toByteArray();
|
|
||||||
return buffer;
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user