use of java.util.jar.Pack200.Packer 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.Packer 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.Packer in project Lucee by lucee.
the class Pack200Util method jar2pack.
public static void jar2pack(InputStream is, OutputStream os, boolean closeIS, boolean closeOS) throws IOException {
// Create the Packer object
Packer packer = Pack200.newPacker();
// Initialize the state by setting the desired properties
Map p = packer.properties();
// take more time choosing codings for better compression
// default is "5"
p.put(Packer.EFFORT, "7");
// use largest-possible archive segments (>10% better compression).
p.put(Packer.SEGMENT_LIMIT, "-1");
// reorder files for better compression.
p.put(Packer.KEEP_FILE_ORDER, Packer.FALSE);
// smear modification times to a single value.
p.put(Packer.MODIFICATION_TIME, Packer.LATEST);
// ignore all JAR deflation requests,
// transmitting a single request to use "store" mode.
p.put(Packer.DEFLATE_HINT, Packer.FALSE);
// discard debug attributes
p.put(Packer.CODE_ATTRIBUTE_PFX + "LineNumberTable", Packer.STRIP);
// throw an error if an attribute is unrecognized
p.put(Packer.UNKNOWN_ATTRIBUTE, Packer.ERROR);
JarInputStream jis = null;
os = new GZIPOutputStream(os);
PrintStream err = System.err;
try {
System.setErr(new PrintStream(new DevNullOutputStream()));
jis = new JarInputStream(is);
packer.pack(jis, os);
} finally {
System.setErr(err);
if (closeIS)
Util.closeEL(jis);
if (closeOS)
Util.closeEL(os);
}
}
use of java.util.jar.Pack200.Packer in project jdk8u_jdk by JetBrains.
the class Pack200Props method verifyDefaults.
private static void verifyDefaults() {
Map<String, String> expectedDefaults = new HashMap<>();
Packer p = Pack200.newPacker();
expectedDefaults.put("com.sun.java.util.jar.pack.default.timezone", p.FALSE);
expectedDefaults.put("com.sun.java.util.jar.pack.disable.native", p.FALSE);
expectedDefaults.put("com.sun.java.util.jar.pack.verbose", "0");
expectedDefaults.put(p.CLASS_ATTRIBUTE_PFX + "CompilationID", "RUH");
expectedDefaults.put(p.CLASS_ATTRIBUTE_PFX + "SourceID", "RUH");
expectedDefaults.put(p.CODE_ATTRIBUTE_PFX + "CharacterRangeTable", "NH[PHPOHIIH]");
expectedDefaults.put(p.CODE_ATTRIBUTE_PFX + "CoverageTable", "NH[PHHII]");
expectedDefaults.put(p.DEFLATE_HINT, p.KEEP);
expectedDefaults.put(p.EFFORT, "5");
expectedDefaults.put(p.KEEP_FILE_ORDER, p.TRUE);
expectedDefaults.put(p.MODIFICATION_TIME, p.KEEP);
expectedDefaults.put(p.SEGMENT_LIMIT, "-1");
expectedDefaults.put(p.UNKNOWN_ATTRIBUTE, p.PASS);
Map<String, String> props = p.properties();
int errors = 0;
for (String key : expectedDefaults.keySet()) {
String def = expectedDefaults.get(key);
String x = props.get(key);
if (x == null) {
System.out.println("Error: key not found:" + key);
errors++;
} else {
if (!def.equals(x)) {
System.out.println("Error: key " + key + "\n value expected: " + def + "\n value obtained: " + x);
errors++;
}
}
}
if (errors > 0) {
throw new RuntimeException(errors + " error(s) encountered in default properties verification");
}
}
use of java.util.jar.Pack200.Packer in project jdk8u_jdk by JetBrains.
the class TestExceptions method pack200Test3.
// test the Pack200.pack(JarInputStream, OutputStream);
static void pack200Test3() {
List<PackTestJarInputStream> tlist = new ArrayList<PackTestJarInputStream>();
try {
// setup the test scenarios
try {
tlist.add(new PackTestJarInputStream((JarInputStream) null, null));
tlist.add(new PackTestJarInputStream((JarInputStream) null, new ByteArrayOutputStream()));
tlist.add(new PackTestJarInputStream(new JarInputStream(new FileInputStream(testJar)), null));
} catch (Exception e) {
throw new Error("Initialization error", e);
}
for (PackTestJarInputStream ti : tlist) {
System.out.println(ti);
try {
Pack200.Packer p = Pack200.newPacker();
p.pack(ti.getJarInputStream(), ti.getOutputStream());
} catch (Exception e) {
ti.checkException(e);
}
}
} finally {
// keep jprt happy
for (PackTestJarInputStream ti : tlist) {
if (ti != null) {
ti.close();
}
}
}
}
Aggregations