use of java.util.jar.Pack200.Unpacker 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.Unpacker 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.Unpacker 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);
}
}
use of java.util.jar.Pack200.Unpacker 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)
Util.closeEL(is);
if (closeOS)
Util.closeEL(jos);
}
}
use of java.util.jar.Pack200.Unpacker in project Spark by igniterealtime.
the class Startup method unpackArchives.
/**
* Converts any pack files in a directory into standard JAR files. Each
* pack file will be deleted after being converted to a JAR. If no
* pack files are found, this method does nothing.
*
* @param libDir the directory containing pack files.
* @param printStatus true if status ellipses should be printed when unpacking.
*/
private void unpackArchives(File libDir, boolean printStatus) {
// Get a list of all packed files in the lib directory.
File[] packedFiles = libDir.listFiles((dir, name) -> {
return name.endsWith(".pack");
});
if (packedFiles == null) {
// Do nothing since no .pack files were found
return;
}
// Unpack each.
boolean unpacked = false;
for (File packedFile : packedFiles) {
try {
String jarName = packedFile.getName().substring(0, packedFile.getName().length() - ".pack".length());
// Delete JAR file with same name if it exists (could be due to upgrade
// from old Wildfire release).
File jarFile = new File(libDir, jarName);
if (jarFile.exists()) {
jarFile.delete();
}
InputStream in = new BufferedInputStream(new FileInputStream(packedFile));
JarOutputStream out = new JarOutputStream(new BufferedOutputStream(new FileOutputStream(new File(libDir, jarName))));
Pack200.Unpacker unpacker = Pack200.newUnpacker();
// Print something so the user knows something is happening.
if (printStatus) {
System.out.print(".");
}
// Call the unpacker
unpacker.unpack(in, out);
in.close();
out.close();
packedFile.delete();
unpacked = true;
} catch (Exception e) {
e.printStackTrace();
}
}
// Print newline if unpacking happened.
if (unpacked && printStatus) {
System.out.println();
}
}
Aggregations