mirror of
https://github.com/GTNewHorizons/CodeChickenCore.git
synced 2026-11-16 01:54:50 +00:00
Added command line tool frontend.
This commit is contained in:
1 parent
7450370d99
commit
ae652f51c2
9 files changed
+396
-23
No files matched your search
@@ -0,0 +1,50 @@
|
||||
package codechicken.lib.tool;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.net.URL;
|
||||
import java.net.URLClassLoader;
|
||||
|
||||
public class StripClassLoader extends URLClassLoader
|
||||
{
|
||||
public StripClassLoader() {
|
||||
super(new URL[0], StripClassLoader.class.getClassLoader());
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<?> loadClass(String name) throws ClassNotFoundException {
|
||||
if(!name.startsWith("codechicken.lib"))
|
||||
return super.loadClass(name);
|
||||
|
||||
try {
|
||||
String resName = name.replace('.', '/')+".class";
|
||||
InputStream res = getResourceAsStream(resName);
|
||||
if(res == null)
|
||||
throw new ClassNotFoundException("Could not find resource: "+resName);
|
||||
byte[] bytes = readFully(res);
|
||||
bytes = transform(bytes);
|
||||
return defineClass(name, bytes, 0, bytes.length);
|
||||
|
||||
} catch(IOException e) {
|
||||
throw new ClassNotFoundException(name, e);
|
||||
}
|
||||
}
|
||||
|
||||
public static byte[] readFully(InputStream is) throws IOException {
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
|
||||
int read;
|
||||
byte[] data = new byte[16384];
|
||||
while ((read = is.read(data, 0, data.length)) > 0)
|
||||
buffer.write(data, 0, read);
|
||||
|
||||
return buffer.toByteArray();
|
||||
}
|
||||
|
||||
private byte[] transform(byte[] bytes) {
|
||||
|
||||
bytes = MCStripTransformer.transform(bytes);
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user