本文整理匯總了Java中net.lingala.zip4j.core.ZipFile.createZipFile方法的典型用法代碼示例。如果您正苦於以下問題:Java ZipFile.createZipFile方法的具體用法?Java ZipFile.createZipFile怎麽用?Java ZipFile.createZipFile使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類net.lingala.zip4j.core.ZipFile
的用法示例。
在下文中一共展示了ZipFile.createZipFile方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createZip
import net.lingala.zip4j.core.ZipFile; //導入方法依賴的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) throws ZipException {
ZipFile zip = new ZipFile(new File(file.getParent(), file.getName() + ".zip"));
ArrayList<File> fileList = new ArrayList<>();
File[] files = file.listFiles();
if (files == null) {
return zip;
}
Arrays.stream(files).forEach(fileList::add);
zip.createZipFile(fileList, new ZipParameters());
return zip;
}
示例2: createZipFile
import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
private File createZipFile(String[] outputFilenames) throws IOException, ZipException {
// We want a temporary filename but the file must not yet exist. So create a temporary file then delete it.
File file = File.createTempFile("outputs", ".zip");
deleteZipFile(file);
ZipFile zipFile = new ZipFile(file);
ZipParameters zipParameters = new ZipParameters();
zipParameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
// Add files to zip file
ArrayList<File> filesToAdd = new ArrayList<>();
for (String outputFilename : outputFilenames) {
File fileToAdd = getFileInWorkingDirectory(outputFilename);
if (fileToAdd.exists()) {
filesToAdd.add(fileToAdd);
} else {
throw new IllegalArgumentException("File does not exist: " + fileToAdd.getAbsolutePath());
}
}
zipFile.createZipFile(filesToAdd, zipParameters);
return file;
}
示例3: example5
import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
/**
* 示例5 創建分卷壓縮包
*/
@Test
public void example5(){
try {
ZipFile zipFile = new ZipFile("src/main/resources/CreateSplitZipFile.zip");
ArrayList<File> filesToAdd = new ArrayList<File>();
filesToAdd.add(new File("src/main/resources/sample.txt"));
filesToAdd.add(new File("src/main/resources/zip4j.txt"));
filesToAdd.add(new File("src/main/resources/zip4j-1.3.2.jar"));
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
zipFile.createZipFile(filesToAdd, parameters, true, 65536);
} catch (ZipException e) {
e.printStackTrace();
}
}
示例4: CreateSplitZipFile
import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
public CreateSplitZipFile() {
try {
// Initiate ZipFile object with the path/name of the zip file.
ZipFile zipFile = new ZipFile("c:\\ZipTest\\CreateSplitZipFile.zip");
// Build the list of files to be added in the array list
// Objects of type File have to be added to the ArrayList
ArrayList filesToAdd = new ArrayList();
filesToAdd.add(new File("c:\\ZipTest\\sample.txt"));
filesToAdd.add(new File("c:\\ZipTest\\myvideo.avi"));
filesToAdd.add(new File("c:\\ZipTest\\mysong.mp3"));
// 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.createZipFile(filesToAdd, parameters, true, 10485760);
} catch (ZipException e) {
e.printStackTrace();
}
}
示例5: writeZip
import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
/**
* Write a ZIP file, handle password protection.
*
* @param file - the ZIP file to write
* @param vd - the VD to write.
*
* @throws VdioException in case of zip problems
*/
protected void writeZip(File file, VD vd) throws VdioException
{
File vdFile = null;
if (!haveZipPassword() && isInteractive())
{
int ret = JOptionPane.showOptionDialog(parentFrame, I18n.getMessage("ProductsWriter.askZipWithoutPass"),
I18n.getMessage("ProductsWriter.confirm"), JOptionPane.YES_NO_CANCEL_OPTION,
JOptionPane.QUESTION_MESSAGE, null, null, Boolean.TRUE);
if (ret == JOptionPane.YES_OPTION)
{
zipPasswd = askZipPassword(false);
}
else if (ret == JOptionPane.CANCEL_OPTION)
{
return;
}
}
try
{
file.delete();
ZipFile zipFile = new ZipFile(file);
vdFile = File.createTempFile("ets_", ".vd_", file.getParentFile());
write(new FileOutputStream(vdFile), vd);
ZipParameters zipParams = new ZipParameters();
zipParams.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_MAXIMUM);
if (haveZipPassword())
{
zipParams.setEncryptFiles(true);
zipParams.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD);
zipParams.setPassword(getZipPassword());
}
zipParams.setFileNameInZip("ets.vd_");
zipFile.createZipFile(vdFile, zipParams);
}
catch (ZipException | IOException e)
{
throw new VdioException(e);
}
finally
{
if (vdFile != null)
vdFile.delete();
}
}
示例6: uploadComponent
import net.lingala.zip4j.core.ZipFile; //導入方法依賴的package包/類
public static boolean uploadComponent(String url, ComponentModel c, IProject project) {
try {
String name = c.getComponent().getName();
File temp = File.createTempFile("bento." + name, ".zip");
/*
java.util.zip.ZipOutputStream zos = new java.util.zip.ZipOutputStream(new FileOutputStream(temp));
ZipEntry entry = new ZipEntry("metamodels");
zos.a
zos.putNextEntry(entry);
*/
temp.delete();
/*
ZipOutputStream outputStream = new ZipOutputStream(new FileOutputStream(temp));
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);
outputStream.putNextEntry(project.getFolder("META-INF").getLocation().toFile(), parameters);
outputStream.closeEntry();
outputStream.finish();
outputStream.close();
*/
ZipFile zipFile = new ZipFile(temp);
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);
ArrayList<File> filesToAdd = new ArrayList<File>();
// To add something, that seems to be compulsory!
filesToAdd.add(project.getFile(".project").getLocation().toFile());
zipFile.createZipFile(filesToAdd, parameters);
// Assume certain structure for the moment!
zipFile.addFolder(project.getFolder("META-INF").getLocation().toPortableString(), parameters);
zipFile.addFolder(project.getFolder("metamodels").getLocation().toPortableString(), parameters);
zipFile.addFolder(project.getFolder("transformation").getLocation().toPortableString(), parameters);
if ( project.getFolder("bindings").exists() )
zipFile.addFolder(project.getFolder("bindings").getLocation().toPortableString(), parameters);
temp.deleteOnExit();
MultipartBody mpart = Unirest.put(url + "/component/" + name).
field("zipped", temp).
field("metadata", asJson(c));
HttpResponse<String> x = mpart.asString();
System.out.println(x.getStatus());
} catch (IOException | ZipException | UnirestException e) {
// showError(e.getMessage());
e.printStackTrace();
return false;
}
return true;
}