本文整理汇总了Java中net.lingala.zip4j.model.ZipParameters.setIncludeRootFolder方法的典型用法代码示例。如果您正苦于以下问题:Java ZipParameters.setIncludeRootFolder方法的具体用法?Java ZipParameters.setIncludeRootFolder怎么用?Java ZipParameters.setIncludeRootFolder使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.lingala.zip4j.model.ZipParameters
的用法示例。
在下文中一共展示了ZipParameters.setIncludeRootFolder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: generateZipFile
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
private void generateZipFile() {
try {
File outputFile = new File(this.workFolder.getName() + ".zip");
if (outputFile.exists()) {
Logger.info(outputFile.getAbsolutePath() + " already exists. Deleting.");
outputFile.delete();
}
ZipFile output = new net.lingala.zip4j.core.ZipFile(outputFile);
Logger.info("Generating " + output.getFile().getAbsolutePath());
ZipParameters params = new ZipParameters();
params.setIncludeRootFolder(false);
params.setRootFolderInZip("");
output.addFolder(this.workFolder.getAbsolutePath() + File.separator + "apktool", params);
params.setRootFolderInZip("classes");
output.addFolder(this.workFolder.getAbsolutePath() + File.separator + "classes", params);
} catch (Throwable t) {
Logger.error("Unable to generate final zip file.", t);
}
}
示例2: compile
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
public static void compile(String pkgroot){
try {
File parent = new File(pkgroot).getParentFile();
String name = new File(pkgroot).getName() + ".atomx";
ZipFile zipFile = new ZipFile(new File(parent, name));
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
parameters.setIncludeRootFolder(false);
zipFile.addFolder(pkgroot, parameters);
} catch (ZipException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
示例3: zipFixture
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
public static File zipFixture(String path) throws ZipException {
File source = new File(path);
File target = new File("target/archives/zip-archive-test.zip");
if (target.exists() && !target.delete())
throw new RuntimeException("Unable to delete old zip file target");
if (!target.getParentFile().exists() && !target.getParentFile().mkdirs())
throw new RuntimeException("Unable to create directories for zip file target");
ZipFile zipFile = new ZipFile(target);
ZipParameters parameters = new ZipParameters();
parameters.setIncludeRootFolder(false);
zipFile.createZipFileFromFolder(source, parameters, false, -1);
return target;
}
示例4: fakeData
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
private MockMultipartFile fakeData() throws IOException, ZipException {
File file = testFolder.newFile();
Files.delete(file.toPath());
ZipFile zipFile = new ZipFile(file);
File dir = testFolder.newFolder();
File metadata = Paths.get(dir.getAbsolutePath(), "metadata.json").toFile();
FileUtils.writeStringToFile(metadata, "metadata");
// Add some random files
File c1 = Paths.get(dir.getAbsolutePath(), "r", "a").toFile();
File c2 = Paths.get(dir.getAbsolutePath(), "a", "c", "b").toFile();
FileUtils.writeStringToFile(c1, "c1");
FileUtils.writeStringToFile(c2, "c2");
//Zip
ZipParameters zipParameters = new ZipParameters();
zipParameters.setIncludeRootFolder(false);
zipFile.createZipFileFromFolder(dir, zipParameters, false, 0);
MockMultipartFile mock = new MockMultipartFile("file", Files.newInputStream(zipFile.getFile().toPath()));
return mock;
}
示例5: zip
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
/**
* Adds a directory to a ZIP-archive.
*
* @param source directory to compress, will not be added itself;
* source directory child files will be placed in the root of archive
* @param destination ZIP-archive
* @param level compression level (0-9)
* @param skipFilter skipped files filter or {@code null} to accept all files
* @throws IOException if any I/O-exception occured
*/
public static void zip(File source, File destination, int level, @Nullable FileFilter skipFilter)
throws IOException {
try {
ZipParameters parameters = new ZipParameters();
parameters.setIncludeRootFolder(false);
parameters.setCompressionLevel(level);
parameters.setReadHiddenFiles(true);
parameters.setDefaultFolderPath(source.getAbsolutePath());
ZipFile zipFile = new ZipFile(destination);
zipFile.addFiles(deepListFilesInDirectory(source, skipFilter, !parameters.isReadHiddenFiles()), parameters);
} catch (ZipException e) {
throw new IOException("Can't add directory to ZIP-file.", e);
}
}
示例6: createZip
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
/**
* Creates a zip from all files and folders in the specified folder. DOES NOT INCLUDE THE FOLDER ITSELF!
*
* @param file the folder which content should be zipped
* @return the created zip
* @throws ZipException if something goes wrong
*/
@Nonnull
public static ZipFile createZip(@Nonnull File file, @Nonnull String name) throws ZipException {
ZipFile zip = new ZipFile(new File(file.getParent(), name + ".zip"));
ZipParameters params = new ZipParameters();
params.setIncludeRootFolder(false);
zip.addFolder(file, params);
return zip;
}
示例7: zipFolder
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
static public void zipFolder(String src, String dst) throws Exception {
File f = new File(dst);
//make dirs if necessary
f.getParentFile().mkdirs();
ZipFile zipfile = new ZipFile(f.getAbsolutePath());
ZipParameters parameters = new ZipParameters();
parameters.setIncludeRootFolder(false);
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
zipfile.addFolder(src, parameters);
}
示例8: zipFiles
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
@Override
public String zipFiles(String zipFilePath, List<File> files, String filesRootPath, boolean includeRootPath) {
String errorMessage = null;
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_FAST);
parameters.setEncryptionMethod(Zip4jConstants.ENC_NO_ENCRYPTION);
parameters.setDefaultFolderPath(filesRootPath);
parameters.setIncludeRootFolder(includeRootPath);
try {
ZipFile zipFile = new ZipFile(zipFilePath);
for (int i = 0; i < files.size(); i++) {
File file = files.get(i);
if (file.isFile()) {
zipFile.addFile(file, parameters);
}
if (file.isDirectory()) {
zipFile.addFolder(file, parameters);
}
}
} catch (ZipException e) {
errorMessage = e.getMessage();
}
return errorMessage;
}
示例9: zipFiles
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
@Override
public String zipFiles(String zipFilePath, List<File> files, String filesRootPath, boolean includeRootPath) {
String errorMessage = null;
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_FAST);
parameters.setEncryptionMethod(Zip4jConstants.ENC_NO_ENCRYPTION);
parameters.setDefaultFolderPath(filesRootPath);
parameters.setIncludeRootFolder(includeRootPath);
try {
ZipFile zipFile = new ZipFile(zipFilePath);
for (int i = 0; i < files.size(); i++) {
File file = files.get(i);
if (file.isFile()) {
zipFile.addFile(file, parameters);
}
if (file.isDirectory()) {
zipFile.addFolder(file, parameters);
}
}
} catch (ZipException e) {
e.printStackTrace();
}
return errorMessage;
}
示例10: createAppPackageFile
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
public static void createAppPackageFile(File fileToBeCreated, File directory) throws ZipException
{
ZipFile zipFile = new ZipFile(fileToBeCreated);
ZipParameters params = new ZipParameters();
params.setIncludeRootFolder(false);
zipFile.addFolder(directory, params);
}
示例11: createConfigPackageFile
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
/**
* Create an confPackage zip using the sample confPackage located in
* src/test/resources/testConfPackage/testConfPackageSrc.
*
* @param file The file whose path will be used to create the confPackage zip
* @return The File object that can be used in the ConfigPackage constructor.
* @throws net.lingala.zip4j.exception.ZipException
*/
public static File createConfigPackageFile(File file) throws net.lingala.zip4j.exception.ZipException
{
ZipFile zipFile = new ZipFile(file);
ZipParameters zipParameters = new ZipParameters();
zipParameters.setIncludeRootFolder(false);
zipFile.createZipFileFromFolder("src/test/resources/testConfigPackage/testConfigPackageSrc", zipParameters, false, Long.MAX_VALUE);
return file;
}
示例12: uploadVersion
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
public void uploadVersion(Version version, int id) throws ZipException, IOException {
HttpPost post = new HttpPost(url + "ai/" + id + "/upload_zip");
File file = new File(System.getProperty("java.io.tmpdir"), version.ai.title + "v" + version.number + System.currentTimeMillis() + ".zip");
ZipFile zip = new ZipFile(file);
ZipParameters params = new ZipParameters();
params.setIncludeRootFolder(false);
zip.createZipFileFromFolder(new File(Paths.versionSrc(version)), params, false, -1);
FileEntity entity = new FileEntity(file);
post.setEntity(entity);
HttpResponse response = http.execute(post);
byte[] output = getOutput(response.getEntity().getContent());
if (output == null) {
throw new IOException("Konnte nicht zum Server verbinden");
}
if (response.getStatusLine().getStatusCode() != 200)
{
if (response.getFirstHeader("Content-Type").getValue().contains("json"))
{
JSONObject json = new JSONObject(new String(output, UTF_8));
String error = json.getString("error");
throw new IllegalStateException(error);
}
else
throw new IllegalStateException("Irgendetwas ist beim Hochladen schief gelaufen.");
}
File image = ((AiSimple) version.ai).getPictureFile();
changeImage(image, id);
}
示例13: writeZip
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
void writeZip(File pkgFile, File packageFolder) throws ZipException {
ZipFile zipFile = new ZipFile(pkgFile);
ZipParameters zipParameters = new ZipParameters();
zipParameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD);
zipParameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
zipParameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
zipParameters.setIncludeRootFolder(false);
zipParameters.setDefaultFolderPath(packageFolder.getAbsolutePath());
zipFile.addFiles(listZipFiles(packageFolder), zipParameters);
}
示例14: buildZip
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
private byte[] buildZip(String content) throws IOException, ZipException {
File dir = testFolder.newFolder();
FileUtils.writeStringToFile(Paths.get(dir.getAbsolutePath(), "metadata.json").toFile(), content);
File zipFile = testFolder.newFile();
Files.delete(zipFile.toPath());
ZipFile zip = new ZipFile(zipFile);
ZipParameters zipParameters = new ZipParameters();
zipParameters.setIncludeRootFolder(false);
zip.createZipFileFromFolder(dir, zipParameters, false, 0);
return FileUtils.readFileToByteArray(zipFile);
}
示例15: zipWorkspace
import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
private void zipWorkspace(Path workingDirectoryPath, Path zipFilePath) throws ZipException {
ZipFile zip = new ZipFile(zipFilePath.toFile());
ZipParameters parameters = new ZipParameters();
parameters.setIncludeRootFolder(false);
zip.createZipFileFromFolder(workingDirectoryPath.toFile(), parameters, false, 0);
}