use of net.lingala.zip4j.ZipFile in project yyl_example by Relucent.
the class Zip4JExample method upzip.
/**
* 解压文件
*/
private static void upzip(File file) throws ZipException, IOException {
ZipFile zipFile = new ZipFile(file);
if (zipFile.isEncrypted()) {
zipFile.setPassword(PASSWORD);
}
for (Object fh : zipFile.getFileHeaders()) {
FileHeader header = (FileHeader) fh;
System.out.println(header.getFileName());
// header.isDirectory()
// ZipInputStream zipInput = zipFile.getInputStream(header);
}
// zip文件名去掉后缀,作为解压的目录名
String path = file.getAbsolutePath();
String destPath = path.substring(0, path.lastIndexOf('.'));
System.out.println("destPath: " + destPath);
zipFile.extractAll(destPath);
}
use of net.lingala.zip4j.ZipFile in project project-build-plugin by axonivy.
the class InstallEngineMojo method unpackEngine.
private void unpackEngine(File downloadZip) throws MojoExecutionException {
try {
String targetLocation = getRawEngineDirectory().getAbsolutePath();
getLog().info("Unpacking engine " + downloadZip.getAbsolutePath() + " to " + targetLocation);
ZipFile engineZip = new ZipFile(downloadZip);
engineZip.extractAll(targetLocation);
} catch (ZipException ex) {
throw new MojoExecutionException("Failed to unpack downloaded engine '" + downloadZip + "'.", ex);
}
}
use of net.lingala.zip4j.ZipFile in project project-build-plugin by axonivy.
the class TestInstallEngineMojo method createFakeEngineZip.
private static File createFakeEngineZip(String ivyVersion) throws IOException, ZipException {
File zipDir = createFakeEngineDir(ivyVersion);
File zipFile = new File(zipDir, "fake.zip");
ZipFile zip = new ZipFile(zipFile);
zip.createSplitZipFileFromFolder(new File(zipDir, OsgiDir.INSTALL_AREA), new ZipParameters(), false, 0);
return zipFile;
}
use of net.lingala.zip4j.ZipFile in project J2ME-Loader by nikita36078.
the class ZipUtils method unzipEntry.
public static void unzipEntry(File srcZip, String name, File dst) throws IOException {
ZipFile zip = new ZipFile(srcZip);
FileHeader entry = zip.getFileHeader(name);
if (entry == null) {
throw new IOException("Entry '" + name + "' not found in zip: " + srcZip);
}
try (BufferedInputStream bis = new BufferedInputStream(zip.getInputStream(entry));
BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(dst), BUFFER_SIZE)) {
byte[] data = new byte[BUFFER_SIZE];
int read;
while ((read = bis.read(data)) != -1) {
bos.write(data, 0, read);
}
}
}
use of net.lingala.zip4j.ZipFile in project J2ME-Loader by nikita36078.
the class AppClassLoader method getResourceBytes.
private static byte[] getResourceBytes(String name) {
if (zipFile == null) {
final File file = new File(oldResDir, name);
try {
FileInputStream fis = new FileInputStream(file);
byte[] data = IOUtils.toByteArray(fis);
fis.close();
return data;
} catch (Exception e) {
Log.w(TAG, "getResourceBytes: from file=" + file, e);
return null;
}
}
DataInputStream dis = null;
try {
FileHeader header = zipFile.getFileHeader(name);
if (header == null) {
return null;
}
dis = new DataInputStream(zipFile.getInputStream(header));
byte[] data = new byte[(int) header.getUncompressedSize()];
dis.readFully(data);
return data;
} catch (ZipException e) {
Log.e(TAG, "getResourceBytes: ", e);
} catch (IOException e) {
Log.e(TAG, "getResourceBytes: ", e);
} finally {
if (dis != null) {
try {
dis.close();
} catch (IOException e) {
Log.e(TAG, "getResourceBytes: ", e);
}
}
}
return null;
}
Aggregations