Java Code Examples for net.lingala.zip4j.core.ZipFile#extractAll()

The following examples show how to use net.lingala.zip4j.core.ZipFile#extractAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ZipManager.java    From AndroidZip with Apache License 2.0 6 votes vote down vote up
/**
 * 解压
 *
 * @param targetZipFilePath     待解压目标文件地址
 * @param destinationFolderPath 解压后文件夹地址
 * @param password              解压密码
 * @param callback              回调
 */
public static void unzip(String targetZipFilePath, String destinationFolderPath, String password, final IZipCallback callback) {
    if (!Zip4jUtil.isStringNotNullAndNotEmpty(targetZipFilePath) || !Zip4jUtil.isStringNotNullAndNotEmpty(destinationFolderPath)) {
        if (callback != null) callback.onFinish(false);
        return;
    }
    ZipLog.debug("unzip: targetZipFilePath=" + targetZipFilePath + " , destinationFolderPath=" + destinationFolderPath + " , password=" + password);
    try {
        ZipFile zipFile = new ZipFile(targetZipFilePath);
        if (zipFile.isEncrypted() && Zip4jUtil.isStringNotNullAndNotEmpty(password)) {
            zipFile.setPassword(password);
        }
        zipFile.setRunInThread(true);
        zipFile.extractAll(destinationFolderPath);
        timerMsg(callback, zipFile);
    } catch (Exception e) {
        if (callback != null) callback.onFinish(false);
        ZipLog.debug("unzip: Exception=" + e.getMessage());
    }
}
 
Example 2
Source File: Utils.java    From sheepit-client with GNU General Public License v2.0 6 votes vote down vote up
public static int unzipFileIntoDirectory(String zipFileName_, String destinationDirectory, String password, Log log)
		throws FermeExceptionNoSpaceLeftOnDevice {
	try {
		ZipFile zipFile = new ZipFile(zipFileName_);
		UnzipParameters unzipParameters = new UnzipParameters();
		unzipParameters.setIgnoreDateTimeAttributes(true);
		
		if (password != null && zipFile.isEncrypted()) {
			zipFile.setPassword(password);
		}
		zipFile.extractAll(destinationDirectory, unzipParameters);
	}
	catch (ZipException e) {
		StringWriter sw = new StringWriter();
		PrintWriter pw = new PrintWriter(sw);
		e.printStackTrace(pw);
		log.debug("Utils::unzipFileIntoDirectory(" + zipFileName_ + "," + destinationDirectory + ") exception " + e + " stacktrace: " + sw.toString());
		return -1;
	}
	return 0;
}
 
Example 3
Source File: Zip4j.java    From maven-framework-project with MIT License 6 votes vote down vote up
/**
 * 示例7 解压压缩文件
 */
@Test
public void example7(){
	
	example4();
	
	try {
           ZipFile zipFile = new ZipFile("src/main/resources/AddFilesWithAESZipEncryption.zip");
           if (zipFile.isEncrypted()) {
               // if yes, then set the password for the zip file
               zipFile.setPassword("123456");
               zipFile.extractAll("src/main/resources/zipfile");
           }
       } catch (ZipException e) {
           e.printStackTrace();
       }
}
 
Example 4
Source File: JReportUtils.java    From bamboobsc with Apache License 2.0 5 votes vote down vote up
public static String selfTestDecompress4Upload(String uploadOid) throws ServiceException, IOException, Exception {
	String extractDir = Constants.getWorkTmpDir() + "/" + JReportUtils.class.getSimpleName() + "/" + SimpleUtils.getUUIDStr() + "/";
	File realFile = UploadSupportUtils.getRealFile(uploadOid);
	try {
		ZipFile zipFile = new ZipFile(realFile);
		zipFile.extractAll( extractDir );
	} catch (Exception e) {
		throw e;
	} finally {
		realFile = null;
	}		
	return extractDir;
}
 
Example 5
Source File: GatewayServer.java    From hadoop-mini-clusters with Apache License 2.0 5 votes vote down vote up
private static void explodeWar(File source, File target) throws IOException, ZipException {
    if (source.isDirectory()) {
        FileUtils.copyDirectory(source, target);
    } else {
        ZipFile zip = new ZipFile(source);
        zip.extractAll(target.getAbsolutePath());
    }
}
 
Example 6
Source File: BusinessProcessManagementUtils.java    From bamboobsc with Apache License 2.0 5 votes vote down vote up
public static File[] decompressResource(File resourceZipFile) throws Exception {
	String extractDir = Constants.getWorkTmpDir() + "/" + BusinessProcessManagementUtils.class.getSimpleName() + "/" + SimpleUtils.getUUIDStr() + "/";
	ZipFile zipFile = new ZipFile(resourceZipFile);
	zipFile.extractAll( extractDir );
	File dir = new File(extractDir);
	return dir.listFiles();
}
 
Example 7
Source File: FileUtil.java    From JavaWeb with Apache License 2.0 5 votes vote down vote up
public static void unZipFile(String zipFilePath,String sourceFilePath,boolean setPassword,String password) throws Exception {
	ZipFile zipFile = new ZipFile(zipFilePath); 
	if(setPassword){
		zipFile.setPassword(password);
	}
    zipFile.extractAll(sourceFilePath);
}
 
Example 8
Source File: FileUtil.java    From JavaWeb with Apache License 2.0 5 votes vote down vote up
public static void unZipFile(String zipFilePath,String sourceFilePath,boolean setPassword,String password) throws Exception {
	ZipFile zipFile = new ZipFile(zipFilePath); 
	if(setPassword){
		zipFile.setPassword(password);
	}
    zipFile.extractAll(sourceFilePath);
}
 
Example 9
Source File: ResumeGenerator.java    From jresume with MIT License 5 votes vote down vote up
private void extractResourcesFromJarFile() throws Exception {
    String classUrl = Main.class.getResource("Main.class").toString();

    URL url = Main.class.getResource("/resources.zip");
    //System.out.println("JAR Resource Zip URL: " + url.toString());
    InputStream inputStream = url.openStream();


    if (config.serverMode) {
        newResourceZip = config.serverInitialResourceZip;
        newResourceFolder = Paths.get("data", "resources").toFile();
    } else {
        newResourceZip = Paths.get(config.outputDirectory, "webresume-resources.zip").toFile();
        newResourceFolder = Paths.get(config.outputDirectory, config.resourceDirectory).toFile();
    }

    if (!newResourceFolder.exists()) {
        newResourceFolder.mkdirs();
    }

    if (newResourceZip.exists()) {
        FileDeleteStrategy.FORCE.delete(newResourceZip);
    }

    Files.copy(inputStream, newResourceZip.toPath());

    ZipFile zipFile = new ZipFile(newResourceZip);
    zipFile.extractAll(newResourceFolder.getAbsolutePath());
}
 
Example 10
Source File: OszUnpacker.java    From opsu-dance with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Extracts the contents of a ZIP archive to a destination.
 * @param file the ZIP archive
 * @param dest the destination directory
 */
private void unzip(File file, File dest) {
	try {
		ZipFile zipFile = new ZipFile(file);
		zipFile.extractAll(dest.getAbsolutePath());
	} catch (ZipException e) {
		String err = String.format("Failed to unzip file %s to dest %s.", file.getAbsolutePath(), dest.getAbsolutePath());
		Log.error(err, e);
		bubNotifs.send(BUB_RED, err);
	}
}
 
Example 11
Source File: Utils.java    From opsu with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Extracts the contents of a ZIP archive to a destination.
 * @param file the ZIP archive
 * @param dest the destination directory
 */
public static void unzip(File file, File dest) {
	try {
		ZipFile zipFile = new ZipFile(file);
		zipFile.extractAll(dest.getAbsolutePath());
	} catch (ZipException e) {
		ErrorHandler.error(String.format("Failed to unzip file %s to dest %s.",
				file.getAbsolutePath(), dest.getAbsolutePath()), e, false);
	}
}
 
Example 12
Source File: ResourcesManager.java    From carnotzet with Apache License 2.0 5 votes vote down vote up
private void copyModuleResources(CarnotzetModule module, Path moduleResourcesPath) {
	try {
		ZipFile f = new ZipFile(module.getJarPath().toFile());
		f.extractAll(moduleResourcesPath.toAbsolutePath().toString());
	}
	catch (ZipException e) {
		throw new CarnotzetDefinitionException(e);
	}

}
 
Example 13
Source File: ResumeGenerator.java    From jresume with MIT License 5 votes vote down vote up
private void extractResourcesFromJarFile() throws Exception {
    String classUrl = Main.class.getResource("Main.class").toString();

    URL url = Main.class.getResource("/resources.zip");
    //System.out.println("JAR Resource Zip URL: " + url.toString());
    InputStream inputStream = url.openStream();


    if (config.serverMode) {
        newResourceZip = config.serverInitialResourceZip;
        newResourceFolder = Paths.get("data", "resources").toFile();
    } else {
        newResourceZip = Paths.get(config.outputDirectory, "webresume-resources.zip").toFile();
        newResourceFolder = Paths.get(config.outputDirectory, config.resourceDirectory).toFile();
    }

    if (!newResourceFolder.exists()) {
        newResourceFolder.mkdirs();
    }

    if (newResourceZip.exists()) {
        FileDeleteStrategy.FORCE.delete(newResourceZip);
    }

    Files.copy(inputStream, newResourceZip.toPath());

    ZipFile zipFile = new ZipFile(newResourceZip);
    zipFile.extractAll(newResourceFolder.getAbsolutePath());
}
 
Example 14
Source File: DesaExportTest.java    From proarc with GNU General Public License v3.0 5 votes vote down vote up
private String extractFile(String fileName, String testName) throws Exception {
    File fileTest = new File(tmp.getRoot().getAbsolutePath() + File.separator + testName);
    fileTest.mkdir();
    ZipFile zipFile = new ZipFile(new File(fileName));
    zipFile.extractAll(fileTest.getAbsolutePath());
    return fileTest.getAbsolutePath();
}
 
Example 15
Source File: FileManager.java    From AndroidProjectCreator with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Works on both ZIP and APK archives
 *
 * @param source ZIP or APK file location
 * @param destination place to extract all files to
 * @throws ZipException if the file is not a ZIP archive
 * @throws IOException if the source file cannot be found
 */
public void extractArchive(String source, String destination) throws ZipException, IOException {
    //Checke if the source folder exists
    if (!new File(source).exists()) {
        throw new IOException("The source file does not exist");
    }
    try {
        ZipFile zipFile = new ZipFile(source);
        zipFile.extractAll(destination);
    } catch (ZipException e) {
        //A message is already provided
        throw new ZipException(e.getMessage());
    }
}
 
Example 16
Source File: ZipUtil.java    From document-management-software with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * This method extracts all entries of a zip-file.
 * 
 * @param zipsource Path of the zip-file.
 * @param target Path of the extracted files.
 * @return True if successfully extracted.
 */
public boolean unzip(String zipsource, String target) {
	boolean result = true;
	try {
		ZipFile zipFile = new ZipFile(zipsource);
		setCharset(zipFile);
		zipFile.extractAll(target);
	} catch (Throwable e) {
		result = false;
		logError(e.getMessage());
	}
	return result;
}
 
Example 17
Source File: WorldModifyCommands.java    From VoxelGamesLibv2 with MIT License 4 votes vote down vote up
@Subcommand("start")
@CommandPermission("%admin")
@Syntax("<world> - the name of the map you want to modify")
public void start(@Nonnull User user, @Nonnull String world) {
    if (editor != null) {
        Lang.msg(user, LangKey.WORLD_CREATOR_IN_USE,
                editor.getDisplayName());
        return;
    }
    editor = user;

    // load data
    Optional<Map> o = worldHandler.getMap(world);
    this.map = o.orElseGet(() -> worldHandler.loadMap(world));

    // load world
    map.load(editor.getUuid(), map.getWorldName());

    File file = new File(worldHandler.getWorldContainer(), map.getLoadedName(editor.getUuid()));

    try {
        ZipFile zip = new ZipFile(new File(worldHandler.getWorldsFolder(), 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().getDisplayName() + "(" + map.getWorldName() + ".zip).", e);
    }

    worldHandler.loadLocalWorld(map.getLoadedName(editor.getUuid()));

    // tp
    user.getPlayer().teleportAsync(map.getCenter().toLocation(map.getLoadedName(user.getUuid())));

    if (gameHandler.getDefaultGame().isParticipating(editor.getUuid())) {
        gameHandler.getDefaultGame().leave(editor, false);
    }
    game = gameHandler.startGame(EditModeGame.GAMEMODE);
    game.getActivePhase().getNextPhase().getFeature(SpawnFeature.class).addSpawn(map.getCenter());
    game.getActivePhase().getNextPhase().getFeature(MapFeature.class).setMap(map);
    map.load(game.getUuid(), map.getWorldName());
    game.join(editor);
    game.endPhase();

    map.getInfo().setWorldName(map.getWorldName());
    Lang.msg(user, LangKey.WORLD_MODIFY_START);
    //TODO use inventory for world creator
}
 
Example 18
Source File: MapReduceIT.java    From geowave with Apache License 2.0 4 votes vote down vote up
@BeforeClass
public static void setupTestData() throws ZipException {
  final ZipFile data = new ZipFile(new File(TEST_DATA_ZIP_RESOURCE_PATH));
  data.extractAll(TEST_DATA_BASE_DIR);
}
 
Example 19
Source File: WorldHandler.java    From VoxelGamesLibv2 with MIT License 4 votes vote down vote up
/**
 * 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().getDisplayName() + " 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().getDisplayName() + " (" + map.getWorldName() + ".zip).", e);
    }

    World world = loadLocalWorld(map.getLoadedName(gameid));

    // load chunks based on markers
    int i = 0;
    int a = 0;
    List<CompletableFuture<Chunk>> futures = new ArrayList<>();
    for (Marker m : map.getMarkers()) {
        Location l = m.getLoc().toLocation(world.getName());
        if (!l.isChunkLoaded()) {
            futures.add(l.getWorld().getChunkAtAsync(l));
            i++;
        } else {
            a++;
        }
    }

    if (replaceMarkers) {
        CompletableFuture.allOf(futures.toArray(new CompletableFuture[0])).thenRun(() -> {
            replaceMarkers(world, map);
        });
    }

    log.finer("Loaded " + i + " chunks and ignored " + a + " already loaded");

    return world;
}
 
Example 20
Source File: FileIO.java    From PHONK with GNU General Public License v3.0 4 votes vote down vote up
static public void unZipFile(String src, String dst) throws ZipException {
    ZipFile zipFile = new ZipFile(src);
    MLog.d(TAG, "--------------> " + src + " " + dst);
    zipFile.extractAll(dst);
}