use of java.util.jar.JarOutputStream in project jdk8u_jdk by JetBrains.
the class UnpackerMemoryTest method main.
public static void main(String[] args) throws Exception {
String name = "foo";
File packFile = new File(name + Utils.PACK_FILE_EXT);
createPackFile(packFile);
if (!packFile.exists()) {
throw new RuntimeException(packFile + " not found");
}
File jarOut = new File(name + ".out");
for (int i = 0; i < 2000; i++) {
JarOutputStream jarOS = null;
FileOutputStream fos = null;
try {
fos = new FileOutputStream(jarOut);
jarOS = new JarOutputStream(fos);
System.out.println("Unpacking[" + i + "]" + packFile);
Utils.unpackn(packFile, jarOS);
} finally {
Utils.close(jarOS);
Utils.close(fos);
}
}
Utils.cleanup();
}
use of java.util.jar.JarOutputStream in project bytecode-viewer by Konloch.
the class JarUtils method saveAsJar.
public static void saveAsJar(Map<String, byte[]> nodeList, String path) {
try (JarOutputStream out = new JarOutputStream(new FileOutputStream(path))) {
ArrayList<String> noDupe = new ArrayList<String>();
for (Entry<String, byte[]> entry : nodeList.entrySet()) {
String name = entry.getKey();
if (!noDupe.contains(name)) {
noDupe.add(name);
out.putNextEntry(new ZipEntry(name));
out.write(entry.getValue());
out.closeEntry();
}
}
for (FileContainer container : BytecodeViewer.files) for (Entry<String, byte[]> entry : container.files.entrySet()) {
String filename = entry.getKey();
if (!filename.startsWith("META-INF")) {
if (!noDupe.contains(filename)) {
noDupe.add(filename);
out.putNextEntry(new ZipEntry(filename));
out.write(entry.getValue());
out.closeEntry();
}
}
}
noDupe.clear();
} catch (IOException e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
}
}
use of java.util.jar.JarOutputStream in project bytecode-viewer by Konloch.
the class JarUtils method saveAsJarClassesOnly.
/**
* Saves a jar without the manifest
* @param nodeList The loaded ClassNodes
* @param path the exact jar output path
*/
public static void saveAsJarClassesOnly(ArrayList<ClassNode> nodeList, String path) {
try (JarOutputStream out = new JarOutputStream(new FileOutputStream(path))) {
ArrayList<String> noDupe = new ArrayList<String>();
for (ClassNode cn : nodeList) {
ClassWriter cw = new ClassWriter(0);
cn.accept(cw);
String name = cn.name + ".class";
if (!noDupe.contains(name)) {
noDupe.add(name);
out.putNextEntry(new ZipEntry(name));
out.write(cw.toByteArray());
out.closeEntry();
}
}
noDupe.clear();
} catch (IOException e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
}
}
use of java.util.jar.JarOutputStream in project bytecode-viewer by Konloch.
the class JarUtils method saveAsJar.
/**
* Saves as jar with manifest
* @param nodeList the loaded ClassNodes
* @param path the exact path of the output jar file
* @param manifest the manifest contents
*/
public static void saveAsJar(ArrayList<ClassNode> nodeList, String path, String manifest) {
try (JarOutputStream out = new JarOutputStream(new FileOutputStream(path))) {
for (ClassNode cn : nodeList) {
ClassWriter cw = new ClassWriter(0);
cn.accept(cw);
out.putNextEntry(new ZipEntry(cn.name + ".class"));
out.write(cw.toByteArray());
out.closeEntry();
}
out.putNextEntry(new ZipEntry("META-INF/MANIFEST.MF"));
out.write((manifest.trim() + "\r\n\r\n").getBytes());
out.closeEntry();
for (FileContainer container : BytecodeViewer.files) for (Entry<String, byte[]> entry : container.files.entrySet()) {
String filename = entry.getKey();
if (!filename.startsWith("META-INF")) {
out.putNextEntry(new ZipEntry(filename));
out.write(entry.getValue());
out.closeEntry();
}
}
} catch (IOException e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
}
}
use of java.util.jar.JarOutputStream in project bytecode-viewer by Konloch.
the class JarUtils method saveAsJarClassesOnly.
public static void saveAsJarClassesOnly(Map<String, byte[]> nodeList, String path) {
try (JarOutputStream out = new JarOutputStream(new FileOutputStream(path))) {
ArrayList<String> noDupe = new ArrayList<String>();
for (Entry<String, byte[]> cn : nodeList.entrySet()) {
String name = cn.getKey();
if (!noDupe.contains(name)) {
noDupe.add(name);
out.putNextEntry(new ZipEntry(name));
out.write(cn.getValue());
out.closeEntry();
}
}
noDupe.clear();
} catch (IOException e) {
new the.bytecode.club.bytecodeviewer.api.ExceptionUI(e);
}
}
Aggregations