当前位置: 首页>>代码示例>>Java>>正文


Java ZipFile.createZipFile方法代码示例

本文整理汇总了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;
}
 
开发者ID:VoxelGamesLib,项目名称:VoxelGamesLib,代码行数:25,代码来源:ZipUtil.java

示例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;
}
 
开发者ID:SEEG-Oxford,项目名称:ABRAID-MP,代码行数:25,代码来源:ModelStatusReporterImpl.java

示例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();
       }
}
 
开发者ID:v5developer,项目名称:maven-framework-project,代码行数:25,代码来源:Zip4j.java

示例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();
	}
}
 
开发者ID:joielechong,项目名称:Zip4jAndroid,代码行数:34,代码来源:CreateSplitZipFile.java

示例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();
   }
}
 
开发者ID:selfbus,项目名称:tools-libraries,代码行数:59,代码来源:ProductsWriter.java

示例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;
}
 
开发者ID:jesusc,项目名称:bento,代码行数:73,代码来源:RemoteRepositoryAccess.java


注:本文中的net.lingala.zip4j.core.ZipFile.createZipFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。