本文整理汇总了Java中org.zeroturnaround.zip.ZipUtil类的典型用法代码示例。如果您正苦于以下问题:Java ZipUtil类的具体用法?Java ZipUtil怎么用?Java ZipUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ZipUtil类属于org.zeroturnaround.zip包,在下文中一共展示了ZipUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: test
import org.zeroturnaround.zip.ZipUtil; //导入依赖的package包/类
@Test
public void test() throws IOException {
PackageWriter packageWriter = new DefaultPackageWriter();
Package pkgtoWrite = createSimplePackage();
Path tempPath = Files.createTempDirectory("tests");
File outputDirectory = tempPath.toFile();
File zipFile = packageWriter.write(pkgtoWrite, outputDirectory);
assertThat(zipFile).exists();
assertThat(zipFile.getName()).isEqualTo("myapp-1.0.0.zip");
ZipUtil.iterate(zipFile, new ZipEntryCallback() {
@Override
public void process(InputStream inputStream, ZipEntry zipEntry) throws IOException {
if (zipEntry.getName().equalsIgnoreCase("package.yml")) {
assertExpectedContents(inputStream, "package.yml");
}
if (zipEntry.getName().equalsIgnoreCase("values.yml")) {
assertExpectedContents(inputStream, "values.yml");
}
if (zipEntry.getName().equals("myapp.yml")) {
assertExpectedContents(inputStream, "generic-template.yml");
}
}
});
}
示例2: write
import org.zeroturnaround.zip.ZipUtil; //导入依赖的package包/类
@Override
public File write(Package pkg, File targetDirectory) {
PackageMetadata packageMetadata = pkg.getMetadata();
File tmpDir = TempFileUtils.createTempDirectory("skipper" + packageMetadata.getName()).toFile();
File rootPackageDir = new File(tmpDir,
String.format("%s-%s", packageMetadata.getName(), packageMetadata.getVersion()));
rootPackageDir.mkdir();
writePackage(pkg, rootPackageDir);
if (!pkg.getDependencies().isEmpty()) {
File packagesDir = new File(rootPackageDir, "packages");
packagesDir.mkdir();
for (Package dependencyPkg : pkg.getDependencies()) {
File packageDir = new File(packagesDir, dependencyPkg.getMetadata().getName());
packageDir.mkdir();
writePackage(dependencyPkg, packageDir);
}
}
File targetZipFile = PackageFileUtils.calculatePackageZipFile(pkg.getMetadata(), targetDirectory);
ZipUtil.pack(rootPackageDir, targetZipFile, true);
FileSystemUtils.deleteRecursively(tmpDir);
return targetZipFile;
}
示例3: 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);
}
}
}
示例4: createZipPackage
import org.zeroturnaround.zip.ZipUtil; //导入依赖的package包/类
protected File createZipPackage() throws Exception {
logInfo("");
logInfo(CREATE_ZIP_START);
final String stageDirectoryPath = mojo.getDeploymentStageDirectory();
final File stageDirectory = new File(stageDirectoryPath);
final File zipPackage = new File(stageDirectoryPath.concat(ZIP_EXT));
if (!stageDirectory.exists()) {
logError(STAGE_DIR_NOT_FOUND);
throw new Exception(STAGE_DIR_NOT_FOUND);
}
ZipUtil.pack(stageDirectory, zipPackage);
logDebug(REMOVE_LOCAL_SETTINGS);
ZipUtil.removeEntry(zipPackage, LOCAL_SETTINGS_FILE);
logInfo(CREATE_ZIP_DONE + stageDirectoryPath.concat(ZIP_EXT));
return zipPackage;
}
示例5: 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);
}
示例6: 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);
}
示例7: 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);
}
}
示例8: compareOfflineAndOnline
import org.zeroturnaround.zip.ZipUtil; //导入依赖的package包/类
public Map<String, List<Map<File, String>>> compareOfflineAndOnline(String onlineZipPath, String offlineDirPath) {
File existFolder = new File(offlineDirPath);
if (!existFolder.exists()) {
return null;
}
Map<String, List<Map<File,String>>> result = new HashMap<>();
result.put("update", new ArrayList<>());
result.put("add", new ArrayList<>());
ZipUtil.iterate(new File(onlineZipPath), new ZipEntryCallback() {
@Override
public void process(InputStream in, ZipEntry zipEntry) throws IOException {
File fileOffline = new File(existFolder,zipEntry.getName());
if(fileOffline.exists()) { // file for merge
if(zipEntry.getCrc() != getCrc(fileOffline.getAbsolutePath())) {
result.get("update").add(inputToMapping(in, fileOffline));
}
} else { // file for add
result.get("add").add(inputToMapping(in, fileOffline));
}
}
});
return result;
}
示例9: 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;
}
示例10: readPackage
import org.zeroturnaround.zip.ZipUtil; //导入依赖的package包/类
public P3Package readPackage(File file) throws PackageException {
try {
if (!ZipUtil.containsEntry(file, "package.json")) {
throw new PackageException("No package schema found");
}
byte[] schemaBytes = ZipUtil.unpackEntry(file, "package.json");
String schemaString = new String(schemaBytes);
JSONObject schema = new JSONObject(schemaString);
P3Package p3 = readSchema(schema);
p3.setLocalPath(file.getPath());
return p3;
}
catch(JSONException e) {
throw new PackageException("Invalid package schema", e);
}
}
示例11: compressZIP
import org.zeroturnaround.zip.ZipUtil; //导入依赖的package包/类
/**
* Compress a list of WorkflowRevision into a ZIP archive
* @param workflowsList the list of workflows to compress
* @return a byte array corresponding to the archive containing the workflows
*/
public byte[] compressZIP(List<WorkflowRevision> workflowsList) {
if (workflowsList == null || workflowsList.size() == 0) {
return null;
}
try (ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream()) {
Stream<ZipEntrySource> streamSources = workflowsList.stream()
.map(workflowRevision -> new ByteSource(getName(workflowRevision),
workflowRevision.getXmlPayload()));
ZipEntrySource[] sources = streamSources.toArray(size -> new ZipEntrySource[size]);
ZipUtil.pack(sources, byteArrayOutputStream);
return byteArrayOutputStream.toByteArray();
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
}
示例12: extractZIP
import org.zeroturnaround.zip.ZipUtil; //导入依赖的package包/类
/**
* Extract workflows from an archive
* @param byteArrayArchive the archive as byte array
* @return the list of Workflows byte arrays
*/
public List<byte[]> extractZIP(byte[] byteArrayArchive) {
List<byte[]> filesList = new ArrayList<>();
if (byteArrayArchive == null) {
return filesList;
}
try (ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(byteArrayArchive)) {
ZipUtil.iterate(byteArrayInputStream, (in, zipEntry) -> process(in, zipEntry, filesList));
} catch (IOException ioe) {
throw new RuntimeException(ioe);
}
return filesList;
}
示例13: 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");
}
示例14: 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");
}
示例15: updateManifest
import org.zeroturnaround.zip.ZipUtil; //导入依赖的package包/类
static void updateManifest(Log pLogger, Map<String, String> pAdditionalManifestEntries, Path pPath) throws IOException
{
String manifestPath = "META-INF/MANIFEST.MF";
Manifest manifest;
byte[] zipContent = ZipUtil.unpackEntry(pPath.toFile(), manifestPath);
if (zipContent == null)
manifest = new Manifest();
else
try (ByteArrayInputStream inputStream = new ByteArrayInputStream(zipContent))
{
manifest = new Manifest(inputStream);
}
Attributes mainAttributes = manifest.getMainAttributes();
if (pAdditionalManifestEntries != null)
for (Map.Entry<String, String> entry : pAdditionalManifestEntries.entrySet())
mainAttributes.putValue(entry.getKey(), entry.getValue());
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream())
{
manifest.write(outputStream);
ZipUtil.replaceEntry(pPath.toFile(), manifestPath, outputStream.toByteArray());
pLogger.info("Updated manifest for " + pPath + ".");
}
}