use of org.topdank.byteengineer.commons.data.JarResource in project maple-ir by LLVM-but-worse.
the class MultiJarDownloader method download.
@Override
public void download() throws IOException {
URL[] urls = new URL[jarInfos.length];
for (int i = 0; i < jarInfos.length; i++) {
urls[i] = new URL(jarInfos[i].formattedURL());
}
contents = new LocateableJarContents<C>(urls);
for (JarInfo jarinfo : jarInfos) {
JarURLConnection connection = (JarURLConnection) new URL(jarinfo.formattedURL()).openConnection();
JarFile jarFile = connection.getJarFile();
Enumeration<JarEntry> entries = jarFile.entries();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
byte[] bytes = IOUtil.read(jarFile.getInputStream(entry));
if (entry.getName().endsWith(".class")) {
C cn = factory.create(bytes, entry.getName());
contents.getClassContents().add(cn);
} else {
JarResource resource = new JarResource(entry.getName(), bytes);
contents.getResourceContents().add(resource);
}
}
}
}
use of org.topdank.byteengineer.commons.data.JarResource in project maple-ir by LLVM-but-worse.
the class SingleJarDownloader method download.
@Override
public void download() throws IOException {
URL url = null;
JarURLConnection connection = (JarURLConnection) (url = new URL(jarInfo.formattedURL())).openConnection();
JarFile jarFile = connection.getJarFile();
Enumeration<JarEntry> entries = jarFile.entries();
contents = new LocateableJarContents<>(url);
Map<String, ClassNode> map = new HashMap<>();
while (entries.hasMoreElements()) {
JarEntry entry = entries.nextElement();
byte[] bytes = read(jarFile.getInputStream(entry));
if (entry.getName().endsWith(".class")) {
C cn = factory.create(bytes, entry.getName());
if (!map.containsKey(cn.name)) {
contents.getClassContents().add(cn);
} else {
throw new IllegalStateException("duplicate: " + cn.name);
}
// if(cn.name.equals("org/xmlpull/v1/XmlPullParser")) {
// System.out.println("SingleJarDownloader.download() " +entry.getName() + " " + bytes.length);
// }
} else {
JarResource resource = new JarResource(entry.getName(), bytes);
contents.getResourceContents().add(resource);
}
}
}
use of org.topdank.byteengineer.commons.data.JarResource in project maple-ir by LLVM-but-worse.
the class CompleteJarDumper method dump.
/**
* Dumps the jars contents.
*
* @param file File to dump it to.
*/
@Override
public void dump(File file) throws IOException {
if (file.exists())
file.delete();
file.createNewFile();
JarOutputStream jos = new JarOutputStream(new FileOutputStream(file));
int classesDumped = 0;
int resourcesDumped = 0;
for (ClassNode cn : contents.getClassContents()) {
classesDumped += dumpClass(jos, cn.name, cn);
}
for (JarResource res : contents.getResourceContents()) {
resourcesDumped += dumpResource(jos, res.getName(), res.getData());
}
if (!Debug.debugging)
System.out.println("Dumped " + classesDumped + " classes and " + resourcesDumped + " resources to " + file.getAbsolutePath());
jos.close();
}
use of org.topdank.byteengineer.commons.data.JarResource in project maple-ir by LLVM-but-worse.
the class CompleteResolvingJarDumper method dump.
/**
* Dumps the jars contents.
*
* @param file File to dump it to.
*/
@Override
public void dump(File file) throws IOException {
if (file.exists())
file.delete();
file.createNewFile();
JarOutputStream jos = new JarOutputStream(new FileOutputStream(file));
int classesDumped = 0;
int resourcesDumped = 0;
for (ClassNode cn : contents.getClassContents()) {
classesDumped += dumpClass(jos, cn.name, cn);
}
for (JarResource res : contents.getResourceContents()) {
resourcesDumped += dumpResource(jos, res.getName(), res.getData());
}
if (!Debug.debugging)
System.out.println("Dumped " + classesDumped + " classes and " + resourcesDumped + " resources to " + file.getAbsolutePath());
jos.close();
}
Aggregations