forked from I2P_Developers/i2p.i2p
* Unzip: Any files in the zip with a .jar.pack or .war.pack extension
will be transparently unpacked with unpack200. Savings is about 60%. Someday we will do this for suds, but we can do it for xpi2ps now. * build: Add updater200 target
This commit is contained in:
@@ -12,9 +12,12 @@ import java.io.OutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Enumeration;
|
||||
import java.util.List;
|
||||
import java.util.jar.JarOutputStream;
|
||||
import java.util.jar.Pack200;
|
||||
import java.util.zip.ZipEntry;
|
||||
import java.util.zip.ZipFile;
|
||||
|
||||
|
||||
/**
|
||||
* General helper methods for messing with files
|
||||
*
|
||||
@@ -75,6 +78,10 @@ public class FileUtil {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* As of release 0.7.12, any files inside the zip that have a .jar.pack or .war.pack suffix
|
||||
* are transparently unpacked to a .jar or .war file using unpack200.
|
||||
*/
|
||||
public static boolean extractZip(File zipfile, File targetDir) {
|
||||
ZipFile zip = null;
|
||||
try {
|
||||
@@ -109,15 +116,22 @@ public class FileUtil {
|
||||
} else {
|
||||
try {
|
||||
InputStream in = zip.getInputStream(entry);
|
||||
FileOutputStream fos = new FileOutputStream(target);
|
||||
int read = 0;
|
||||
while ( (read = in.read(buf)) != -1) {
|
||||
fos.write(buf, 0, read);
|
||||
if (entry.getName().endsWith(".jar.pack") || entry.getName().endsWith(".war.pack")) {
|
||||
target = new File(targetDir, entry.getName().substring(0, entry.getName().length() - ".pack".length()));
|
||||
JarOutputStream fos = new JarOutputStream(new FileOutputStream(target));
|
||||
Pack200.newUnpacker().unpack(in, fos);
|
||||
fos.close();
|
||||
System.err.println("INFO: File [" + entry.getName() + "] extracted and unpacked");
|
||||
} else {
|
||||
FileOutputStream fos = new FileOutputStream(target);
|
||||
int read = 0;
|
||||
while ( (read = in.read(buf)) != -1) {
|
||||
fos.write(buf, 0, read);
|
||||
}
|
||||
fos.close();
|
||||
System.err.println("INFO: File [" + entry.getName() + "] extracted");
|
||||
}
|
||||
fos.close();
|
||||
in.close();
|
||||
|
||||
System.err.println("INFO: File [" + entry.getName() + "] extracted");
|
||||
} catch (IOException ioe) {
|
||||
System.err.println("ERROR: Error extracting the zip entry (" + entry.getName() + "]");
|
||||
ioe.printStackTrace();
|
||||
|
Reference in New Issue
Block a user