本文整理匯總了Java中net.lingala.zip4j.core.ZipFile.extractAll方法的典型用法代碼示例。如果您正苦於以下問題:Java ZipFile.extractAll方法的具體用法?Java ZipFile.extractAll怎麽用?Java ZipFile.extractAll使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.lingala.zip4j.core.ZipFile
的用法示例。
在下文中一共展示了ZipFile.extractAll方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: unzipfile
import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
public void unzipfile(File zipfile, String dest, String passwd) throws ZipException {
ZipFile zfile = new ZipFile(zipfile);
// zfile.setFileNameCharset("GBK");//在GBK係統中需要設置
if (!zfile.isValidZipFile()) {
throw new ZipException("壓縮文件不合法,可能已經損壞!");
}
File file = new File(dest);
if (file.isDirectory() && !file.exists()) {
file.mkdirs();
}
if (zfile.isEncrypted()) {
zfile.setPassword(passwd.toCharArray());
}
zfile.extractAll(dest);
}
示例2: loadWorld
import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
/**
* Loads a world. Needs to copy the file from the repo, unzip it and let the implementation load it <br><b>Always
* needs to call super! Super needs to be called first (because it copies the world)</b>
*
* @param map the map that should be loaded
* @param gameid the id of the game this map belongs to
* @return the loaded world
* @throws WorldException something goes wrong
*/
@Nonnull
public World loadWorld(@Nonnull Map map, @Nonnull UUID gameid, boolean replaceMarkers) {
map.load(gameid, "TEMP_" + map.getWorldName() + "_" + gameid.toString().split("-")[0]);
log.finer("Loading map " + map.getInfo().getName() + " as " + map.getLoadedName(gameid));
File file = new File(worldContainer, map.getLoadedName(gameid));
try {
ZipFile zip = new ZipFile(new File(worldsFolder, map.getWorldName() + ".zip"));
zip.extractAll(file.getAbsolutePath());
FileUtils.delete(new File(file, "uid.dat"));
} catch (ZipException e) {
throw new WorldException("Could not unzip world " + map.getInfo().getName() + ".", e);
}
World world = loadLocalWorld(map.getLoadedName(gameid));
if (replaceMarkers) {
replaceMarkers(world, map);
}
return world;
}
示例3: decompressZipFile
import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
public void decompressZipFile(String appName, String filename, String password) {
String filePath = Environment.getExternalStorageDirectory() + "/" + appName;
try {
File src = new File(filePath, filename);
ZipFile zipFile = new ZipFile(src);
if (zipFile.isEncrypted())
zipFile.setPassword(password);
zipFile.extractAll(filePath);
} catch (ZipException e) {
e.printStackTrace();
}
}
示例4: testZipSourceBuildSpec
import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
@Test
public void testZipSourceBuildSpec() throws Exception {
clearSourceDirectory();
String buildSpecName = "Buildspec.yml";
File buildSpec = new File("/tmp/source/" + buildSpecName);
String buildSpecContents = "yo\n";
FileUtils.write(buildSpec, buildSpecContents);
ZipOutputStream out = new ZipOutputStream(new FileOutputStream("/tmp/source.zip"));
S3DataManager dataManager = createDefaultSource();
dataManager.zipSource(testZipSourceWorkspace, "/tmp/source/", out, "/tmp/source/");
out.close();
File zip = new File("/tmp/source.zip");
assertTrue(zip.exists());
File unzipFolder = new File("/tmp/folder/");
unzipFolder.mkdir();
ZipFile z = new ZipFile(zip.getPath());
z.extractAll(unzipFolder.getPath());
assertTrue(unzipFolder.list().length == 1);
assertEquals(buildSpecName, unzipFolder.list()[0]);
File extractedBuildSpec = new File(unzipFolder.getPath() + "/" + buildSpecName);
assertTrue(FileUtils.readFileToString(extractedBuildSpec).equals(buildSpecContents));
}
示例5: downloadDump
import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
@Before
public void downloadDump() throws IOException, ZipException {
// TODO use released version of demo dump
URL website = new URL("https://repo.gentics.com/artifactory/lan.releases/com/gentics/mesh/mesh-demo/0.6.18/mesh-demo-0.6.18-dump.zip");
FileUtils.deleteDirectory(targetDir);
ReadableByteChannel rbc = Channels.newChannel(website.openStream());
File zipFile = new File("target" + File.separator + "dump.zip");
FileOutputStream fos = new FileOutputStream(zipFile);
try {
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
} finally {
fos.close();
}
ZipFile zip = new ZipFile(zipFile);
zip.extractAll(targetDir.getAbsolutePath());
zipFile.delete();
}
示例6: downloadAndExtractZip
import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
private File downloadAndExtractZip(File folder, String command) throws IOException, ZipException {
File tempZip = File.createTempFile("codr", System.currentTimeMillis() + ".zip");
downloadFile(tempZip, command);
ZipFile zipFile = new ZipFile(tempZip);
tempZip.deleteOnExit();
File zip;
zipFile.extractAll((zip = Files.createTempDirectory("codrUnzipped" + System.currentTimeMillis()).toFile()).getAbsolutePath());
zip.deleteOnExit();
for (File file : zip.listFiles()) {
if (file.isFile()) {
FileUtils.copyFile(file, new File(folder, file.getName()));
} else {
new File(folder, file.getName()).mkdirs();
FileUtils.copyDirectory(file, new File(folder, file.getName()));
}
}
return folder;
}
示例7: unzipToFolder
import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
public static String unzipToFolder(String zip) {
try {
File tempDir = new File("temp");
if (!tempDir.exists()) {
tempDir.mkdir();
}
File folderName = new File(String.format("%s/%d%d", tempDir.getPath(), System.currentTimeMillis(), new Random().nextInt()));
if (!folderName.exists()) {
folderName.mkdir();
}
System.out.println(zip);
ZipFile zipFile = new ZipFile(zip);
zipFile.extractAll(folderName.getAbsolutePath());
return folderName.getAbsolutePath();
} catch (ZipException ex) {
Logger.getLogger(Unzipper.class.getName()).log(Level.SEVERE, null, ex);
}
return null;
}
示例8: handle
import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
/**
* Retrieve the specification file from the remote resource.
*
* @param file The downloaded file resource
* @return The RAML specification file
* @throws java.lang.IllegalAccessError Target directory could not be created.
* @throws java.lang.IllegalArgumentException The target directory is not a directory
* @throws java.lang.IllegalStateException The target directory could not be written to or the specification file was not found.
*/
@Override
public File handle(File file) {
try {
String targetPath = FilenameUtils.separatorsToUnix(targetDirectory.getPath());
if (!targetDirectory.exists() && !targetDirectory.mkdirs())
throw new IllegalAccessError(String.format("Could not create [ %s ] directory.", targetPath));
if (targetDirectory.exists() && !targetDirectory.isDirectory())
throw new IllegalArgumentException(String.format("[ %s ] is not a directory.", targetPath));
if (targetDirectory.exists() && !targetDirectory.canWrite())
throw new IllegalStateException(String.format("Cannot write to [ %s ].", targetPath));
ZipFile zipFile = new ZipFile(file);
zipFile.extractAll(targetDirectory.getPath());
if (!specificationFile.exists() || !specificationFile.canRead())
throw new IllegalStateException(String.format("Could not find or access [ %s ].", FilenameUtils.separatorsToUnix(specificationFile.getPath())));
return specificationFile;
} catch (ZipException e) {
throw new RuntimeException(e);
}
}
示例9: extractFileContent
import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
/**
* Extracts archive content to temp dir and process content.
*
* @param name
* @param file
* @param path
* @return Application based on archive content
* @throws ZipException
* @throws IOException
* @throws ObjectNotFoundException
*/
public Application extractFileContent(String name, MultipartFile file, String path)
throws ZipException, IOException, ObjectNotFoundException {
if (!checkFileFormat(file, path)) {
logger.error("File format is wrong.");
return null;
}
String source = getFullFileName(path, file) + file.getOriginalFilename();
File destinationFolder = new File(getFullFileName(path, file));
if (!destinationFolder.exists()) {
if(!destinationFolder.mkdirs()) {
throw new IOException("Cant create folders");
}
}
ZipFile zipFile = new ZipFile(source);
zipFile.extractAll(destinationFolder.getPath());
if (!checkAppContent(destinationFolder.getPath())) {
logger.error("App content is wrong.");
return null;
}
return extractAppContent(name, path, destinationFolder.getPath(), file);
}
示例10: saveRequestBodyToTemporaryDir
import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
private File saveRequestBodyToTemporaryDir(MultipartFile modelRunZip) throws IOException, ZipException {
File tempDataDir = null;
File zipFile = null;
try {
zipFile = Files.createTempFile("run", ".zip").toFile();
modelRunZip.transferTo(zipFile);
ZipFile zip = new ZipFile(zipFile);
tempDataDir = Files.createTempDirectory("run").toFile();
zip.extractAll(tempDataDir.toString());
return tempDataDir;
} catch (Exception e) {
if (tempDataDir != null && tempDataDir.exists()) {
FileUtils.deleteDirectory(tempDataDir);
}
throw e;
} finally {
if (zipFile != null && zipFile.exists()) {
Files.delete(zipFile.toPath());
}
}
}
示例11: restoreProjectSaikuDB
import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
private boolean restoreProjectSaikuDB(){
boolean restoredSaiku = false;
if( getZippedSaikuProjectDB().exists() ){
// Unzip file
try {
ZipFile zippedProjectSaikuData = new ZipFile( getZippedSaikuProjectDB() );
zippedProjectSaikuData.extractAll( FolderFinder.getCollectEarthDataFolder() );
restoredSaiku = true;
} catch (ZipException e) {
logger.error("Problems unzipping the contents of the zipped Saiku DB to the local user folder ", e);
}
}
return restoredSaiku;
}
示例12: unzip
import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
/**
* 使用給定密碼解壓指定的ZIP壓縮文件到指定目錄
* <p>
* 如果指定目錄不存在,可以自動創建,不合法的路徑將導致異常被拋出
* @param dest 解壓目錄
* @param passwd ZIP文件的密碼
* @return 解壓後文件數組
* @throws ZipException 壓縮文件有損壞或者解壓縮失敗拋出
*/
public static File [] unzip(File zipFile, String dest, String passwd) throws ZipException {
ZipFile zFile = new ZipFile(zipFile);
zFile.setFileNameCharset("GBK");
if (!zFile.isValidZipFile()) {
throw new ZipException("壓縮文件不合法,可能被損壞.");
}
File destDir = new File(dest);
if (destDir.isDirectory() && !destDir.exists()) {
destDir.mkdir();
}
if (zFile.isEncrypted()) {
zFile.setPassword(passwd.toCharArray());
}
zFile.extractAll(dest);
List<FileHeader> headerList = zFile.getFileHeaders();
List<File> extractedFileList = new ArrayList<File>();
for(FileHeader fileHeader : headerList) {
if (!fileHeader.isDirectory()) {
extractedFileList.add(new File(destDir,fileHeader.getFileName()));
}
}
File [] extractedFiles = new File[extractedFileList.size()];
extractedFileList.toArray(extractedFiles);
return extractedFiles;
}
示例13: unzip
import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
/**
* Unzips the .dpkg if it's not already unzipped.
* @throws ZipException if an error happens when unzipping
*/
private void unzip() throws ZipException {
File tempDir = Files.createTempDir();
ZipFile zipFile = new ZipFile(apgkFilePath);
zipFile.extractAll(tempDir.getAbsolutePath());
unzippedToFolder = tempDir;
}
示例14: unzipSavegames
import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
private void unzipSavegames(String cemuDirectory, File outputFile) {
try {
ZipFile zipFile = new ZipFile(outputFile);
zipFile.extractAll(cemuDirectory + "/mlc01/usr");
outputFile.delete();
LOGGER.info("unzip successfull");
} catch (ZipException e) {
LOGGER.error("an error occurred during unziping the file!", e);
}
}
示例15: unzip
import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
public static void unzip(String targetZipFilePath, String destinationFolderPath, String password) {
try {
ZipFile zipFile = new ZipFile(targetZipFilePath);
if (zipFile.isEncrypted()) {
zipFile.setPassword(password);
}
zipFile.extractAll(destinationFolderPath);
} catch (Exception e) {
e.printStackTrace();
}
}