當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。