本文整理匯總了Java中org.zeroturnaround.zip.ZipUtil.unpack方法的典型用法代碼示例。如果您正苦於以下問題:Java ZipUtil.unpack方法的具體用法?Java ZipUtil.unpack怎麽用?Java ZipUtil.unpack使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.zeroturnaround.zip.ZipUtil
的用法示例。
在下文中一共展示了ZipUtil.unpack方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: templateFromFile
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
@FXML
void templateFromFile() {
FileChooser fileChooser = new FileChooser();
fileChooser.setInitialDirectory(Preferences.getPath("lastTemplateDir").toFile());
fileChooser.setTitle("Import template");
fileChooser.getExtensionFilters().addAll(
new ExtensionFilter("CYOA Studio Template", "*.cyoatemplate"),
new ExtensionFilter("All files", "*"));
File selected = fileChooser.showOpenDialog(stage);
if (selected != null) {
try {
Preferences.setPath("lastTemplateDir", selected.toPath().getParent());
Path tempDirectory = Files.createTempDirectory(null);
ZipUtil.unpack(selected, tempDirectory.toFile());
loadTemplate(tempDirectory);
FileUtils.deleteDirectory(tempDirectory.toFile());
} catch (Exception e) {
showError("Could not load template", e);
}
}
}
示例2: unzipResource
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
public static void unzipResource(String sourcePath, String outputDirectory) {
InputStream is = FunnyCreator.class.getResourceAsStream(sourcePath);
if (is == null) {
throw new RuntimeException("Resource " + sourcePath + " not found");
}
File output = new File(outputDirectory);
if (!output.exists()) {
if (!output.mkdir()) {
throw new RuntimeException("Cannot create directory");
}
}
ZipUtil.unpack(is, output);
}
示例3: unzipResource
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
public static void unzipResource(String sourcePath, String outputDirectory) {
InputStream is = NanoMaven.class.getResourceAsStream(sourcePath);
if (is == null) {
throw new RuntimeException("Resource " + sourcePath + " not found");
}
File output = new File(outputDirectory);
if (!output.exists()) {
if (!output.mkdir()) {
throw new RuntimeException("Cannot create directory");
}
}
ZipUtil.unpack(is, output);
}
示例4: uploadRepository
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
public void uploadRepository(Long id, MultipartFile file) {
try {
File saveSolutionFile = saveSolutionFile(id, file);
// the p2-repository will be unpacked into the solution root folder
File p2repo = getSolutionFile(id.toString());
// delete the old stuff
FileUtils.deleteDirectory(new File(p2repo, "features"));
FileUtils.deleteDirectory(new File(p2repo, "plugins"));
FileUtils.deleteQuietly(new File(p2repo, "content.jar"));
FileUtils.deleteQuietly(new File(p2repo, "artifacts.jar"));
FileUtils.deleteQuietly(new File(p2repo, "content.xml"));
FileUtils.deleteQuietly(new File(p2repo, "artifacts.xml"));
// unpack to root folder
ZipUtil.unpack(saveSolutionFile, p2repo);
// and delete the uploaded zip-file
FileUtils.deleteQuietly(saveSolutionFile);
} catch (Exception e) {
throw new InternalErrorException(e);
}
}
示例5: runStep
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
@Override
public boolean runStep(P3Package p3, PackageContext ctx, JSONObject config) {
File path = Paths.get(Bootstrap.getHomeDir().getPath(), "assets", p3.getId(), p3.getVersion()).toFile();
if(path.exists() && path.isDirectory()) {
log.info("Not expanding asset package (already exists)");
return true;
}
log.info("Expanding asset package to " + path.getPath());
try {
ZipUtil.unpack(new File(p3.getLocalPath()), path);
}
catch(ZipException e) {
log.error("Unable to expand package", e);
return false;
}
return true;
}
示例6: shouldZipLocalResources
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
@Test
public void shouldZipLocalResources() {
ResourceFolder uploadFolder = new ResourceFolder("upload");
File file = uploadFolder.toZip();
File tempDir = Files.createTempDir();
ZipUtil.unpack(file, tempDir);
verifyFilesInZip(tempDir,
"upload",
"upload/first.txt",
"upload/directory",
"upload/directory/second.txt",
"upload/directory/dir",
"upload/directory/dir/third.txt");
}
示例7: shouldZipExternalResources_HierarchicalFolderCase
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
@Test
public void shouldZipExternalResources_HierarchicalFolderCase() {
ResourceFolder uploadFolder = new ResourceFolder("hierarchy");
File file = uploadFolder.toZip();
File tempDir = Files.createTempDir();
ZipUtil.unpack(file, tempDir);
verifyFilesInZip(tempDir,
"hierarchy/level0.txt",
"hierarchy/level1",
"hierarchy/level1/level1.txt",
"hierarchy/level1/level2",
"hierarchy/level1/level2/level2.txt",
"hierarchy/level1.1/level1.1.txt",
"hierarchy/level1.1/level2.2",
"hierarchy/level1.1/level2.2/level2.2.txt");
}
示例8: initPythonDir
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
private static void initPythonDir(File pyDir) throws Exception {
if (pyDir.exists())
FileUtils.deleteDirectory(pyDir);
pyDir.mkdirs();
String pyJar = "libs/jython-standalone-2.7.0.jar";
try (InputStream is = RcpActivator.getStream(pyJar)) {
ZipUtil.unpack(is, pyDir, (entry) -> {
if (entry.startsWith("Lib/") && entry.length() > 4) {
return entry.substring(4);
} else {
return null;
}
});
}
File file = new File(pyDir, ".version");
Files.write(file.toPath(), Config.VERSION.getBytes("utf-8"));
}
示例9: extractFolder
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
private static void extractFolder(Bundle bundle, String zipPath)
throws Exception {
File dir = getDir(bundle);
if (dir.exists())
FileUtils.deleteDirectory(dir);
dir.mkdirs();
writeVersion(bundle);
InputStream zipStream = FileLocator.openStream(bundle,
new Path(zipPath), false);
File zipFile = new File(dir, "@temp.zip");
try (FileOutputStream out = new FileOutputStream(zipFile)) {
IOUtils.copy(zipStream, out);
}
ZipUtil.unpack(zipFile, dir);
if (!zipFile.delete())
zipFile.deleteOnExit();
}
示例10: deserializePackageFromDatabase
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
private Package deserializePackageFromDatabase(PackageMetadata packageMetadata) {
// package file was uploaded to a local DB hosted repository
Path tmpDirPath = null;
try {
tmpDirPath = TempFileUtils.createTempDirectory("skipper");
File targetPath = new File(tmpDirPath + File.separator + packageMetadata.getName());
targetPath.mkdirs();
File targetFile = PackageFileUtils.calculatePackageZipFile(packageMetadata, targetPath);
try {
StreamUtils.copy(packageMetadata.getPackageFile().getPackageBytes(), new FileOutputStream(targetFile));
}
catch (IOException e) {
throw new SkipperException(
"Could not copy package file for " + packageMetadata.getName() + "-"
+ packageMetadata.getVersion() +
" from database to target file " + targetFile,
e);
}
ZipUtil.unpack(targetFile, targetPath);
Package pkgToReturn = this.packageReader.read(new File(targetPath, packageMetadata.getName() + "-" +
packageMetadata.getVersion()));
pkgToReturn.setMetadata(packageMetadata);
return pkgToReturn;
}
finally {
if (tmpDirPath != null && !FileSystemUtils.deleteRecursively(tmpDirPath.toFile())) {
logger.warn("Temporary directory can not be deleted: " + tmpDirPath);
}
}
}
示例11: upload
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
@Transactional
public PackageMetadata upload(UploadRequest uploadRequest) {
validateUploadRequest(uploadRequest);
Repository localRepositoryToUpload = getRepositoryToUpload(uploadRequest.getRepoName());
Path packageDirPath = null;
try {
packageDirPath = TempFileUtils.createTempDirectory("skipperUpload");
File packageDir = new File(packageDirPath + File.separator + uploadRequest.getName());
packageDir.mkdir();
Path packageFile = Paths
.get(packageDir.getPath() + File.separator + uploadRequest.getName() + "-"
+ uploadRequest.getVersion() + "." + uploadRequest.getExtension());
Assert.isTrue(packageDir.exists(), "Package directory doesn't exist.");
Files.write(packageFile, uploadRequest.getPackageFileAsBytes());
ZipUtil.unpack(packageFile.toFile(), packageDir);
String unzippedPath = packageDir.getAbsolutePath() + File.separator + uploadRequest.getName()
+ "-" + uploadRequest.getVersion();
File unpackagedFile = new File(unzippedPath);
Assert.isTrue(unpackagedFile.exists(), "Package is expected to be unpacked, but it doesn't exist");
Package packageToUpload = this.packageReader.read(unpackagedFile);
PackageMetadata packageMetadata = packageToUpload.getMetadata();
if (localRepositoryToUpload != null) {
packageMetadata.setRepositoryId(localRepositoryToUpload.getId());
packageMetadata.setRepositoryName(localRepositoryToUpload.getName());
}
packageMetadata.setPackageFile(new PackageFile((uploadRequest.getPackageFileAsBytes())));
return this.packageMetadataRepository.save(packageMetadata);
}
catch (IOException e) {
throw new SkipperException("Failed to upload the package.", e);
}
finally {
if (packageDirPath != null && !FileSystemUtils.deleteRecursively(packageDirPath.toFile())) {
logger.warn("Temporary directory can not be deleted: " + packageDirPath);
}
}
}
示例12: retrieveMd5s
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
private Map<String, byte[]> retrieveMd5s() {
try {
Future<Path> md5FileFuture = perform(() -> downloadFile(MD5_FILE));
Path md5File = AsyncUtil.getResult(md5FileFuture);
Path md5TempPath = appConfig.getBaseServerPath().resolve(MD5_TEMP_PATH);
ZipUtil.unpack(md5File.toFile(), md5TempPath.toFile());
return Files.walk(md5TempPath)
.collect(
HashMap<String, byte[]>::new,
(map, path) -> {
try {
Path relativeToBase = md5TempPath.relativize(path);
String fileName = relativeToBase.getFileName().toString().replaceAll("\\.md5$", "");
if (relativeToBase.getParent() != null) {
fileName = relativeToBase.getParent().resolve(fileName).toString();
}
byte[] md5 = Files.readAllBytes(path);
map.put(fileName, md5);
} catch (IOException ignored) {
}
},
HashMap::putAll
);
} catch (IOException | ExecutionException | ZipException e) {
LOGGER.warn("Error while creating MD5 table");
LogUtil.stacktrace(LOGGER, e);
return Collections.emptyMap();
}
}
示例13: extractFile
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
private void extractFile(Path file) {
LOGGER.debug("Extracting file: {}", file);
Path relativePath = appConfig.getSyncPath().relativize(file);
Path parentBaseDir = appConfig.getBaseServerPath().resolve(relativePath).getParent();
ZipUtil.unpack(file.toFile(), parentBaseDir.toFile());
LOGGER.debug("Extract finished");
}
示例14: unpack
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
public void unpack(String path) throws RestoreException
{
File[] fileList = new File(path).listFiles( );
if (fileList.length != 1)
{
LOG.error("There is 0 or more then 1 files in the restore folder {}",
path);
Throwables.propagate(new RestoreException("There is 0 or more then 1 files in the restore folder. Please drop in only Zip file "));
}
if (fileList[0].getName( ).endsWith("zip"))
{
File source = new File(backupStruct.getSourcePath( ) + File.separator + fileList[0].getName( ));
if (source.canRead( ) && source.canWrite( ))
{
ZipUtil.unpack(source, new File(backupStruct.getSourcePath( ) + File.separator + RESTORE_FOLDER));
}
else
{
LOG.error("Please check permission on file {} ",
backupStruct.getSourcePath( ) + File.separator + fileList[0].getName( ));
Throwables.propagate(new RestoreException("File permission problem "));
}
}
else
{
LOG.error("There is no zip file in {} ", path);
throw new RestoreException("Please check zip file");
}
}
示例15: unzipOnlineContent
import org.zeroturnaround.zip.ZipUtil; //導入方法依賴的package包/類
public static File unzipOnlineContent(String zipFilePath, String destFolder) {
String dirname = Paths.get(zipFilePath).getFileName().toString();
dirname = dirname.substring(0, dirname.length() - 4);
// create output directory is not exists
File folder = new File(destFolder + File.separator + dirname);
log.debug("Tentative de dezippage de " + zipFilePath + " dans " + folder.getAbsolutePath());
if (!folder.exists()) {
folder.mkdir();
log.info("Dézippage dans " + folder.getAbsolutePath() + " réalisé avec succès");
} else {
log.debug("Le répertoire dans lequel vous souhaitez dezipper existe déjà ");
}
ZipUtil.unpack(new File(zipFilePath), folder);
return folder;
}