本文整理汇总了Java中net.lingala.zip4j.core.ZipFile.createZipFileFromFolder方法的典型用法代码示例。如果您正苦于以下问题:Java ZipFile.createZipFileFromFolder方法的具体用法?Java ZipFile.createZipFileFromFolder怎么用?Java ZipFile.createZipFileFromFolder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类net.lingala.zip4j.core.ZipFile
的用法示例。
在下文中一共展示了ZipFile.createZipFileFromFolder方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: zipFixture
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的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;
}
示例2: fakeData
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的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;
}
示例3: CreateSplitZipFileFromFolder
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
public CreateSplitZipFileFromFolder() {
try {
// Initiate ZipFile object with the path/name of the zip file.
ZipFile zipFile = new ZipFile("c:\\ZipTest\\CreateSplitZipFileFromFolder.zip");
// Initiate Zip Parameters which define various properties such
// as compression method, etc.
ZipParameters parameters = new ZipParameters();
// set compression method to store compression
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
// Set the compression level. This value has to be in between 0 to 9
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
// Create a split file by setting splitArchive parameter to true
// and specifying the splitLength. SplitLenth has to be greater than
// 65536 bytes
// Please note: If the zip file already exists, then this method throws an
// exception
zipFile.createZipFileFromFolder("C:\\ZipTest", parameters, true, 10485760);
} catch (ZipException e) {
e.printStackTrace();
}
}
示例4: createConfigPackageFile
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的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;
}
示例5: uploadVersion
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的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);
}
示例6: createFakeEngineZip
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的package包/类
private static File createFakeEngineZip(String ivyVersion) throws IOException, ZipException
{
File zipDir = createFakeEngineDir(ivyVersion);
File zipFile = new File(zipDir, "fake.zip");
ZipFile zip = new ZipFile(zipFile);
zip.createZipFileFromFolder(new File(zipDir, OsgiDir.INSTALL_AREA), new ZipParameters(), false, 0);
return zipFile;
}
示例7: buildZip
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的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);
}
示例8: zipWorkspace
import net.lingala.zip4j.core.ZipFile; //导入方法依赖的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);
}