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


Java ZipParameters.setFileNameInZip方法代码示例

本文整理汇总了Java中net.lingala.zip4j.model.ZipParameters.setFileNameInZip方法的典型用法代码示例。如果您正苦于以下问题:Java ZipParameters.setFileNameInZip方法的具体用法?Java ZipParameters.setFileNameInZip怎么用?Java ZipParameters.setFileNameInZip使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在net.lingala.zip4j.model.ZipParameters的用法示例。


在下文中一共展示了ZipParameters.setFileNameInZip方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: loadJar

import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
public void loadJar(File jar) throws IOException {
    try {
        final ZipFile zipFile = new ZipFile(classFile);
        final ZipFile jarFile = new ZipFile(jar);
        //noinspection unchecked
        for (FileHeader header : (List<FileHeader>) jarFile.getFileHeaders()) {
            if (!header.isDirectory()) {
                final ZipParameters parameters = new ZipParameters();
                parameters.setFileNameInZip(header.getFileName());
                parameters.setSourceExternalStream(true);
                zipFile.addStream(jarFile.getInputStream(header), parameters);
            }
        }
        dexJar();
    } catch (ZipException e) {
        IOException exception = new IOException();
        //noinspection UnnecessaryInitCause
        exception.initCause(e);
        throw exception;
    }
}
 
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:22,代码来源:AndroidClassLoader.java

示例2: defineClass

import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public Class<?> defineClass(String name, byte[] data) {
    try {
        final ZipFile zipFile = new ZipFile(classFile);
        final ZipParameters parameters = new ZipParameters();
        parameters.setFileNameInZip(name.replace('.', '/') + ".class");
        parameters.setSourceExternalStream(true);
        zipFile.addStream(new ByteArrayInputStream(data), parameters);
        return dexJar().loadClass(name, parent);
    } catch (IOException | ZipException e) {
        throw new FatalLoadingException(e);
    } finally {
        dexFile.delete();
        odexOatFile.delete();
    }
}
 
开发者ID:feifadaima,项目名称:https-github.com-hyb1996-NoRootScriptDroid,代码行数:20,代码来源:AndroidClassLoader.java

示例3: addFileToZip

import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
public static ZipFile addFileToZip(String fileToCompress, File srcFile, String fileNameInZip )
		throws ZipException {
	File destBackupFile = new File( fileToCompress );	
	ZipFile zipBackupFile = new ZipFile( destBackupFile );

	ZipParameters zipParameters = new ZipParameters();
	// COMP_DEFLATE is for compression
	zipParameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
	// DEFLATE_LEVEL_ULTRA = maximum compression
	zipParameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_ULTRA);
	zipParameters.setSourceExternalStream(true);
	zipParameters.setFileNameInZip( fileNameInZip );				
	zipBackupFile.addFile(srcFile, zipParameters);

	return zipBackupFile;
}
 
开发者ID:openforis,项目名称:collect-earth,代码行数:17,代码来源:CollectEarthUtils.java

示例4: zip

import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
/**
 * 使用给定密码压缩指定文件或文件夹到指定位置.
 * <p>
 * dest可传最终压缩文件存放的绝对路径,也可以传存放目录,也可以传null或者"".<br />
 * 如果传null或者""则将压缩文件存放在当前目录,即跟源文件同目录,压缩文件名取源文件名,以.zip为后缀;<br />
 * 如果以路径分隔符(File.separator)结尾,则视为目录,压缩文件名取源文件名,以.zip为后缀,否则视为文件名.
 * @param src 要压缩的文件或文件夹路径
 * @param dest 压缩文件存放路径
 * @param isCreateDir 是否在压缩文件里创建目录,仅在压缩文件为目录时有效.<br />
 * 如果为false,将直接压缩目录下文件到压缩文件.
 * @param passwd 压缩使用的密码
 * @return 最终的压缩文件存放的绝对路径,如果为null则说明压缩失败.
 */
public static String zip(String src, String dest, boolean isCreateDir, String passwd) {
    File srcFile = new File(src);
    File destFile = new File(dest);
    dest = buildDestinationZipFilePath(srcFile, dest);
    ZipParameters parameters = new ZipParameters();
    parameters.setFileNameInZip(destFile.getName().substring(0,destFile.getName().lastIndexOf("."))+".log");
    parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);           // 压缩方式
    parameters.setSourceExternalStream(true);
    parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);    // 压缩级别
    if (!TextUtils.isEmpty(passwd)) {
        parameters.setEncryptFiles(true);
        parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD); // 加密方式
        parameters.setPassword(passwd.toCharArray());
    }
    try {
        ZipFile zipFile = new ZipFile(dest);
        if (srcFile.isDirectory()) {
            // 如果不创建目录的话,将直接把给定目录下的文件压缩到压缩文件,即没有目录结构
            if (!isCreateDir) {
                File [] subFiles = srcFile.listFiles();
                ArrayList<File> temp = new ArrayList<File>();
                Collections.addAll(temp, subFiles);
                zipFile.addFiles(temp, parameters);
                return dest;
            }
            zipFile.addFolder(srcFile, parameters);
        } else {
            zipFile.addFile(srcFile, parameters);
        }
        return dest;
    } catch (ZipException e) {
        e.printStackTrace();
    }
    return null;
}
 
开发者ID:SavorGit,项目名称:Hotspot-master-devp,代码行数:49,代码来源:ZipUtil.java

示例5: InitZipParametersFileName

import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
/**
 * 
 * @param f

 * @return ZipParameters
 */
private static ZipParameters InitZipParametersFileName(File f) {
	
	// Initiate Zip Parameters which define various properties such
	// as compression method, etc. More parameters are explained in other
	// examples
	ZipParameters zp = new ZipParameters();
	
	// set compression method to deflate compression
	zp.setCompressionMethod(Zip4jConstants.COMP_DEFLATE); 
	
	/* 
	 Set the compression level. This value has to be in between 0 to 9
	 Several predefined compression levels are available
	 DEFLATE_LEVEL_FASTEST - Lowest compression level but higher speed of compression
	 DEFLATE_LEVEL_FAST - Low compression level but higher speed of compression
	 DEFLATE_LEVEL_NORMAL - Optimal balance between compression level/speed
	 DEFLATE_LEVEL_MAXIMUM - High compression level with a compromise of speed
	 DEFLATE_LEVEL_ULTRA - Highest compression level but low speed
	*/
	zp.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL); 
	
	// set this flag to true. If this flag is true, Zip4j identifies that
	// the data will not be from a file but directly from a stream
	zp.setSourceExternalStream(true);
	
	zp.setRootFolderInZip(f.getPath() + File.separator);
	
	zp.setFileNameInZip(f.toString());
	
	return zp;
}
 
开发者ID:Comcast,项目名称:Oscar,代码行数:38,代码来源:Zip.java

示例6: addPrjFileToArchive

import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
/**
 *
 * @param file
 * @param targetCrs
 * @return
 * @throws ZipException
 * @throws IOException
 * @throws NoSuchAuthorityCodeException
 * @throws FactoryException
 */
public static File addPrjFileToArchive(File file, String targetCrs)
		throws ZipException, IOException, NoSuchAuthorityCodeException, FactoryException {

	ZipFile zipFile = new ZipFile(file);

	CoordinateReferenceSystem decodedTargetCrs = CRS.decode(targetCrs);
	String targetCrsWkt = toSingleLineWKT(decodedTargetCrs);

	ArrayList<String> zipFileNames = new ArrayList<String>();
	List<FileHeader> zipFileHeaders = zipFile.getFileHeaders();

	for (FileHeader zipFileHeader : zipFileHeaders){
		if (FilenameUtils.getExtension(zipFileHeader.getFileName()).equalsIgnoreCase("prj")) {
			continue;
		}
		zipFileNames.add(FilenameUtils.getBaseName(zipFileHeader.getFileName()));
	}

	LOG.debug("Following files will be created and added to ZIP file: " + zipFileNames);

	for (String prefix : zipFileNames) {
		File targetPrj = null;
		try {
			targetPrj = File.createTempFile("TMP_" + prefix, ".prj");
			FileUtils.write(targetPrj, targetCrsWkt, "UTF-8");
			ZipParameters params = new ZipParameters();
			params.setSourceExternalStream(true);
			params.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
			params.setFileNameInZip(prefix + ".prj");
			zipFile.addFile(targetPrj, params);
		} finally {
			if (targetPrj != null) {
				targetPrj.delete();
			}
		}
	}

	return zipFile.getFile();
}
 
开发者ID:terrestris,项目名称:shogun2,代码行数:50,代码来源:GeoServerRESTImporter.java

示例7: doInBackground

import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
@Override
protected ProgressModel doInBackground(Void... params) {
    List<AppsModel> appsModelList;
    if (appsModels == null) {
        appsModelList = new AppListCreator(context).getAppList();
    } else {
        appsModelList = appsModels;
    }
    if (appsModelList == null) {
        return onError("Apps Are Empty, Please select ones");
    }
    ProgressModel progressModel = new ProgressModel();
    progressModel.setMax(appsModelList.size());
    publishProgress(progressModel);
    try {
        FileUtil fileUtil = new FileUtil();
        File zipFileName = new File(fileUtil.getBaseFolderName() + "backup.zip");
        File zipFileData = new File(fileUtil.getBaseFolderName() + "data.zip");
        zipFile = new ZipFile(zipFileName);
        zipData = new ZipFile(zipFileData);
        if (!zipData.isValidZipFile()) {
            if (zipData.getFile() != null && zipData.getFile().exists())
                zipData.getFile().delete();
        }
        if (!zipFile.isValidZipFile()) {
            if (zipFile.getFile() != null && zipFile.getFile().exists())
                zipFile.getFile().delete();
        }
        int count = 0;
        boolean withData = AppHelper.isBackupData(context);
        if (withData) RootManager.getInstance().obtainPermission();
        for (AppsModel model : appsModelList) {
            if (isCancelled()) {
                return onError("cancelled");
            }
            if (model != null) {
                ApplicationInfo packageInfo = context.getPackageManager().getApplicationInfo(model.getPackageName(), 0);
                File file = new File(packageInfo.sourceDir);
                if (file.exists()) {
                    count++;
                    File fileToSave = fileUtil.generateFile(model.getAppName());
                    progressModel = new ProgressModel();
                    progressModel.setProgress(count);
                    progressModel.setFileName(fileToSave.getName());
                    publishProgress(progressModel);
                    ZipParameters parameters = new ZipParameters();
                    parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
                    parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_FASTEST);
                    parameters.setSourceExternalStream(true);
                    parameters.setFileNameInZip(fileToSave.getName().replaceAll(" ", ""));
                    zipFile.addFile(file, parameters);
                    progressModel = new ProgressModel();
                    progressModel.setProgress(count);
                    progressModel.setFileName(fileToSave.getName());
                    publishProgress(progressModel);
                }
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
        return onError(e.getMessage());
    }

    return null;
}
 
开发者ID:k0shk0sh,项目名称:KAM,代码行数:66,代码来源:BackupAppsTasker.java

示例8: writeZip

import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的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

示例9: getParams

import net.lingala.zip4j.model.ZipParameters; //导入方法依赖的package包/类
protected ZipParameters getParams(String password, String fileNameInZip, DeflateLevel defLevel) {
    ZipParameters params = new ZipParameters();
    {
        int dl;
        if (defLevel == null) {
            dl = Zip4jConstants.DEFLATE_LEVEL_NORMAL;
        } else {
            switch (defLevel) {
                case FASTEST:
                    dl = Zip4jConstants.DEFLATE_LEVEL_FASTEST;
                    break;
                case FAST:
                    dl = Zip4jConstants.DEFLATE_LEVEL_FAST;
                    break;
                case NORMAL:
                    dl = Zip4jConstants.DEFLATE_LEVEL_NORMAL;
                    break;
                case MAXIMUM:
                    dl = Zip4jConstants.DEFLATE_LEVEL_MAXIMUM;
                    break;
                case ULTRA:
                    dl = Zip4jConstants.DEFLATE_LEVEL_ULTRA;
                    break;
                default:
                    throw new IllegalStateException();
            }
        }
        params.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
        params.setCompressionLevel(dl);
    }
    if (fileNameInZip != null) {
        params.setSourceExternalStream(true);
        params.setFileNameInZip(fileNameInZip);
    }
    if (password != null) {
        params.setEncryptFiles(true);
        params.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
        params.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);
        params.setPassword(password);
    }
    return params;
}
 
开发者ID:brightgenerous,项目名称:brigen-base,代码行数:43,代码来源:ZipDelegaterZip4j.java


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