use of java.util.jar.Pack200 in project lwjgl by LWJGL.
the class AppletLoader method extractPack.
/**
* Extract Pack File
* @param in Input path to pack file
* @param out output path to resulting file
* @throws Exception if any errors occur
*/
protected void extractPack(String in, String out) throws Exception {
File f = new File(in);
FileOutputStream fostream = new FileOutputStream(out);
JarOutputStream jostream = new JarOutputStream(fostream);
try {
Pack200.Unpacker unpacker = Pack200.newUnpacker();
unpacker.unpack(f, jostream);
} finally {
jostream.close();
fostream.close();
}
// delete pack file as its no longer needed
f.delete();
}
use of java.util.jar.Pack200 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 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();
}
}
}
}
use of java.util.jar.Pack200 in project jdk8u_jdk by JetBrains.
the class PackageVersionTest method verifyPack.
static void verifyPack(String filename, int expected_major, int expected_minor) {
File jarFileName = new File("test.jar");
jarFileName.delete();
String[] jargs = { "cvf", jarFileName.getName(), filename };
Utils.jar(jargs);
JarFile jfin = null;
try {
jfin = new JarFile(jarFileName);
Packer packer = Pack200.newPacker();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
packer.pack(jfin, baos);
baos.flush();
baos.close();
byte[] buf = baos.toByteArray();
int minor = buf[4] & 0x000000ff;
int major = buf[5] & 0x000000ff;
if (major != expected_major || minor != expected_minor) {
String msg = String.format("test fails: expected:%d.%d but got %d.%d\n", expected_major, expected_minor, major, minor);
throw new Error(msg);
}
System.out.println(filename + ": OK");
} catch (IOException ioe) {
throw new RuntimeException(ioe.getMessage());
} finally {
Utils.close((Closeable) jfin);
}
}
use of java.util.jar.Pack200 in project jdk8u_jdk by JetBrains.
the class PackageVersionTest method verify6991164.
static void verify6991164() {
Unpacker unpacker = Pack200.newUnpacker();
String versionStr = unpacker.toString();
String expected = "Pack200, Vendor: " + System.getProperty("java.vendor") + ", Version: " + JAVA7_PACKAGE_MAJOR_VERSION + "." + JAVA7_PACKAGE_MINOR_VERSION;
if (!versionStr.equals(expected)) {
System.out.println("Expected: " + expected);
System.out.println("Obtained: " + versionStr);
throw new RuntimeException("did not get expected string " + expected);
}
}
Aggregations