use of java.util.jar.Pack200 in project jdk8u_jdk by JetBrains.
the class Utils method pack.
// given a jar file foo.jar will write to foo.pack
static void pack(JarFile jarFile, File packFile) throws IOException {
Pack200.Packer packer = Pack200.newPacker();
Map<String, String> p = packer.properties();
// Take the time optimization vs. space
// CAUTION: do not use 0.
p.put(packer.EFFORT, "1");
// Make the memory consumption as effective as possible
p.put(packer.SEGMENT_LIMIT, "10000");
// ignore all JAR deflation requests to save time
p.put(packer.DEFLATE_HINT, packer.FALSE);
// save the file ordering of the original JAR
p.put(packer.KEEP_FILE_ORDER, packer.TRUE);
FileOutputStream fos = null;
try {
// Write out to a jtreg scratch area
fos = new FileOutputStream(packFile);
// Call the packer
packer.pack(jarFile, fos);
} finally {
close(fos);
}
}
use of java.util.jar.Pack200 in project jdk8u_jdk by JetBrains.
the class T7007157 method main.
public static void main(String... args) throws IOException {
File sdkHome = Utils.JavaSDK;
File testJar = new File(new File(sdkHome, "lib"), "tools.jar");
JarFile jarFile = new JarFile(testJar);
File packFile = new File("foo.pack");
Pack200.Packer packer = Pack200.newPacker();
Map<String, String> p = packer.properties();
// Take the time optimization vs. space
// CAUTION: do not use 0.
p.put(packer.EFFORT, "1");
// Make the memory consumption as effective as possible
p.put(packer.SEGMENT_LIMIT, "10000");
// ignore all JAR deflation requests to save time
p.put(packer.DEFLATE_HINT, packer.FALSE);
// save the file ordering of the original JAR
p.put(packer.KEEP_FILE_ORDER, packer.TRUE);
// strip the StackMapTables
p.put(packer.CODE_ATTRIBUTE_PFX + "StackMapTable", packer.STRIP);
FileOutputStream fos = null;
try {
// Write out to a jtreg scratch area
fos = new FileOutputStream(packFile);
// Call the packer
packer.pack(jarFile, fos);
} finally {
Utils.close(fos);
Utils.close(jarFile);
}
Utils.cleanup();
}
use of java.util.jar.Pack200 in project jdk8u_jdk by JetBrains.
the class TestExceptions method unpack200Test2.
// test the Pack200.unpack(File, OutputStream);
static void unpack200Test2() {
List<UnpackTestFileInput> tlist = new ArrayList<UnpackTestFileInput>();
try {
// setup the test scenarios
try {
tlist.add(new UnpackTestFileInput((File) null, null));
tlist.add(new UnpackTestFileInput(testPackFile, null));
tlist.add(new UnpackTestFileInput((File) null, new JarOutputStream(new ByteArrayOutputStream())));
} catch (Exception e) {
throw new Error("Initialization error", e);
}
// test the scenarios
for (UnpackTestFileInput ti : tlist) {
System.out.println(ti);
try {
Pack200.Unpacker unpacker = Pack200.newUnpacker();
unpacker.unpack(ti.getInputFile(), ti.getJarOutputStream());
} catch (Exception e) {
ti.checkException(e);
}
}
} finally {
// keep jprt happy
for (TestInput ti : tlist) {
if (ti != null) {
ti.close();
}
}
}
}
use of java.util.jar.Pack200 in project jdk8u_jdk by JetBrains.
the class TestExceptions method unpack200Test1.
// test the Pack200.unpack(InputStream, OutputStream);
static void unpack200Test1() {
List<UnpackTestInput> tlist = new ArrayList<UnpackTestInput>();
try {
// setup the test scenarios
try {
tlist.add(new UnpackTestInput((InputStream) null, null));
tlist.add(new UnpackTestInput(new FileInputStream(testPackFile), null));
tlist.add(new UnpackTestInput((InputStream) null, new JarOutputStream(new ByteArrayOutputStream())));
} catch (Exception e) {
throw new Error("Initialization error", e);
}
// test the scenarios
for (UnpackTestInput ti : tlist) {
System.out.println(ti);
try {
Pack200.Unpacker unpacker = Pack200.newUnpacker();
unpacker.unpack(ti.getInputStream(), ti.getJarOutputStream());
} catch (Exception e) {
ti.checkException(e);
}
}
} finally {
// keep jprt happy
for (TestInput ti : tlist) {
if (ti != null) {
ti.close();
}
}
}
}
use of java.util.jar.Pack200 in project Lucee by lucee.
the class Pack200Util method pack2Jar.
public static void pack2Jar(InputStream is, OutputStream os, boolean closeIS, boolean closeOS) throws IOException {
Unpacker unpacker = Pack200.newUnpacker();
SortedMap<String, String> p = unpacker.properties();
p.put(Unpacker.DEFLATE_HINT, Unpacker.TRUE);
is = new GZIPInputStream(is);
JarOutputStream jos = null;
try {
jos = new JarOutputStream(os);
unpacker.unpack(is, jos);
jos.finish();
} finally {
if (closeIS)
IOUtil.closeEL(is);
if (closeOS)
IOUtil.closeEL(jos);
}
}
Aggregations