gpt4 book ai didi

net.lingala.zip4j.model.ZipParameters类的使用及代码示例

转载 作者:知者 更新时间:2024-03-15 18:02:40 28 4
gpt4 key购买 nike

本文整理了Java中net.lingala.zip4j.model.ZipParameters类的一些代码示例,展示了ZipParameters类的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。ZipParameters类的具体详情如下:
包路径:net.lingala.zip4j.model.ZipParameters
类名称:ZipParameters

ZipParameters介绍

暂无

代码示例

代码示例来源:origin: stackoverflow.com

ZipParameters parameters = new ZipParameters();
     parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE); // set compression method to deflate compression
//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
     parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
     //Set the encryption flag to true
     parameters.setEncryptFiles(true);
     //Set the encryption method to AES Zip Encryption
     parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_AES);
     //AES_STRENGTH_128 - For both encryption and decryption
     //AES_STRENGTH_192 - For decryption only
     //AES_STRENGTH_256 - For both encryption and decryption
     //Key strength 192 cannot be used for encryption. But if a zip file already has a
     //file encrypted with key strength of 192, then Zip4j can decrypt this file
     parameters.setAesKeyStrength(Zip4jConstants.AES_STRENGTH_256);

代码示例来源:origin: net.lingala.zip4j/zip4j

/**
 * Sets the password for the zip file or the file being added<br>
 * <b>Note</b>: For security reasons, usage of this method is discouraged. Use 
 * setPassword(char[]) instead. As strings are immutable, they cannot be wiped
 * out from memory explicitly after usage. Therefore, usage of Strings to store 
 * passwords is discouraged. More info here: 
 * http://docs.oracle.com/javase/1.5.0/docs/guide/security/jce/JCERefGuide.html#PBEEx
 * @param password
 */
public void setPassword(String password) {
  if (password == null) return;
  setPassword(password.toCharArray());
}

代码示例来源:origin: stackoverflow.com

public void EmployeeEncyrptedZipFileDownload(HttpServletResponse response, @RequestParam(value = "id", required = true) int employeeId) throws IOException, ZipException
{
  //Prepare text file contents
  String fileContent = "Hallo Welt";

  response.setContentType("application/zip");
  response.setHeader("Content-Disposition", "attachment;filename=test.zip");

  final StringBuilder sb = new StringBuilder(fileContent);
  final ZipOutputStream zout = new ZipOutputStream(response.getOutputStream());

  ZipParameters zipParameters = new ZipParameters();
  zipParameters.setSourceExternalStream(true);
  zipParameters.setFileNameInZip("mytext.txt");

  zout.putNextEntry(null, zipParameters);
  byte[] data = sb.toString().getBytes();
  zout.write(data, 0, data.length);

  zout.closeEntry();
  zout.finish();
}

代码示例来源:origin: stackoverflow.com

net.lingala.zip4j.core.ZipFile zipFile = new ZipFile("out.zip");
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
zipFile.createZipFileFromFolder("path/to/source/dir", parameters, true, maximum size);

代码示例来源:origin: stackoverflow.com

ZipParameters zp = new ZipParameters();
zp.setFileNameInZip("sample.zip");
System.out.println(zp.getCompressionMethod());
System.out.println(Zip4jConstants.COMP_DEFLATE);

OutPut:
8
8

代码示例来源:origin: stackoverflow.com

ZipParameters zipParams = new ZipParameters();
zipParams.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
zipParams.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
zipParams.setEncryptFiles(true);
zipParams.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD);
zipParams.setPassword(pass);
zipParams.setSourceExternalStream(true);
zipParams.setFileNameInZip(fileName);

代码示例来源:origin: net.lingala.zip4j/zip4j

public void putNextEntry(File file, ZipParameters zipParameters) throws ZipException {
  if (!zipParameters.isSourceExternalStream() && file == null) {
    throw new ZipException("input file is null");
  if (!zipParameters.isSourceExternalStream() && !Zip4jUtil.checkFileExists(file)) {
    throw new ZipException("input file does not exist");
    this.zipParameters = (ZipParameters)zipParameters.clone();
    if (!zipParameters.isSourceExternalStream()) {
      if (sourceFile.isDirectory()) {
        this.zipParameters.setEncryptFiles(false);
        this.zipParameters.setEncryptionMethod(-1);
        this.zipParameters.setCompressionMethod(Zip4jConstants.COMP_STORE);
      if (!Zip4jUtil.isStringNotNullAndNotEmpty(this.zipParameters.getFileNameInZip())) {
        throw new ZipException("file name is empty for external stream");
      if (this.zipParameters.getFileNameInZip().endsWith("/") || 
          this.zipParameters.getFileNameInZip().endsWith("\\")) {
        this.zipParameters.setEncryptFiles(false);
        this.zipParameters.setEncryptionMethod(-1);
        this.zipParameters.setCompressionMethod(Zip4jConstants.COMP_STORE);
    if (this.zipParameters.isEncryptFiles()) {
      initEncrypter();
      if (encrypter != null) {
        if (zipParameters.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_STANDARD) {
          byte[] headerBytes = ((StandardEncrypter)encrypter).getHeaderBytes();
          outputStream.write(headerBytes);

代码示例来源:origin: stackoverflow.com

long _start = System.currentTimeMillis();
ZipFile _zipFile =  new ZipFile(System.nanoTime()+".zip");
ZipParameters _parameters = new ZipParameters();
_parameters.setCompressionMethod(Zip4jConstants.COMP_STORE);
_parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_FASTEST);
_parameters.setIncludeRootFolder(false);
ArrayList<File> _files = new ArrayList<File>();
for(int j=1;j<5;j++){
  long start = System.currentTimeMillis();
  ZipFile zipFile =  new ZipFile(System.nanoTime()+".zip");
  ZipParameters parameters = new ZipParameters();
  parameters.setCompressionMethod(Zip4jConstants.COMP_STORE);
  parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_FASTEST);
  parameters.setIncludeRootFolder(false);
  ArrayList<File> files = new ArrayList<File>();
  for(int j=1;j<5;j++){

代码示例来源:origin: stackoverflow.com

ZipParameters parameters = new ZipParameters();
parameters.setIncludeRootFolder(true);
zipFile.removeFile(fh);
zipFile.addFolder(new File(tempdir.toFile(), "META-INF"), parameters);

代码示例来源:origin: net.lingala.zip4j/zip4j

if ((parameters.getCompressionMethod() != Zip4jConstants.COMP_STORE) && 
    parameters.getCompressionMethod() != Zip4jConstants.COMP_DEFLATE) {
  throw new ZipException("unsupported compression type");
if (parameters.getCompressionMethod() == Zip4jConstants.COMP_DEFLATE) {
  if (parameters.getCompressionLevel() < 0 && parameters.getCompressionLevel() > 9) {
    throw new ZipException("invalid compression level. compression level dor deflate should be in the range of 0-9");
if (parameters.isEncryptFiles()) {
  if (parameters.getEncryptionMethod() != Zip4jConstants.ENC_METHOD_STANDARD && 
      parameters.getEncryptionMethod() != Zip4jConstants.ENC_METHOD_AES) {
    throw new ZipException("unsupported encryption method");
  if (parameters.getPassword() == null || parameters.getPassword().length <= 0) {
    throw new ZipException("input password is empty or null");
  parameters.setAesKeyStrength(-1);
  parameters.setEncryptionMethod(-1);

代码示例来源:origin: dwatling/apk-decompiler

private void generateZipFile() {
  try {
    File outputFile = new File(this.workFolder.getName() + ".zip");
    if (outputFile.exists()) {
      Logger.info(outputFile.getAbsolutePath() + " already exists. Deleting.");
      outputFile.delete();
    }
    ZipFile output = new net.lingala.zip4j.core.ZipFile(outputFile);
    Logger.info("Generating " + output.getFile().getAbsolutePath());
    ZipParameters params = new ZipParameters();
    params.setIncludeRootFolder(false);
    params.setRootFolderInZip("");
    output.addFolder(this.workFolder.getAbsolutePath() + File.separator + "apktool", params);
    params.setRootFolderInZip("classes");
    output.addFolder(this.workFolder.getAbsolutePath() + File.separator + "classes", params);
  } catch (Throwable t) {
    Logger.error("Unable to generate final zip file.", t);
  }
}

代码示例来源:origin: net.lingala.zip4j/zip4j

ZipParameters fileParameters = (ZipParameters) parameters.clone();
  if (fileParameters.isEncryptFiles() && fileParameters.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_STANDARD) {
    progressMonitor.setCurrentOperation(ProgressMonitor.OPERATION_CALC_CRC);
    fileParameters.setSourceFileCRC((int)CRCUtil.computeFileCRC(((File)fileList.get(i)).getAbsolutePath(), progressMonitor));
    progressMonitor.setCurrentOperation(ProgressMonitor.OPERATION_ADD);
    fileParameters.setCompressionMethod(Zip4jConstants.COMP_STORE);

代码示例来源:origin: org.jboss.forge.addon/resources-impl

ZipParameters parameters = new ZipParameters();
for (File directory : directories)

代码示例来源:origin: com.tomitribe.tribestream/tribestream-container

public byte[] createZip(final ZipContent content,
            final String password) {
  final ZipParameters parameters = new ZipParameters();
  parameters.setEncryptFiles(true);
  parameters.setPassword(password);
  parameters.setEncryptionMethod(Zip4jConstants.ENC_METHOD_STANDARD); // AES is good but poorly supported by zip UIs
  parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
  parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
    if (content.files != null) {
      for (final File f : content.files) {
        parameters.setFileNameInZip(f.getName()); // drop the name
        zip.addFile(f, parameters);
      for (final FileContent c : content.contents) {
        try (final InputStream stream = new ByteArrayInputStream(c.content)) {
          parameters.setSourceExternalStream(true);
          parameters.setFileNameInZip(c.name);
          zip.addStream(stream, parameters);
        } catch (final IOException e) { // more than unlikely

代码示例来源:origin: stackoverflow.com

ZipFile zipfile = new ZipFile("/mnt/sdcard/bla.zip");
ZipParameters parameters = new ZipParameters();
parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
zipfile.addFolder("/mnt/sdcard/folderToZip", parameters);

代码示例来源:origin: com.github.axet/zip4j

public void putNextEntry(NativeStorage file, ZipParameters zipParameters) throws ZipException {
  if (!zipParameters.isSourceExternalStream() && file == null) {
    throw new ZipException("input file is null");
  if (!zipParameters.isSourceExternalStream() && !Zip4jUtil.checkFileExists(file)) {
    throw new ZipException("input file does not exist");
    this.zipParameters = (ZipParameters)zipParameters.clone();
    if (!zipParameters.isSourceExternalStream()) {
      if (sourceFile.isDirectory()) {
        this.zipParameters.setEncryptFiles(false);
        this.zipParameters.setEncryptionMethod(-1);
        this.zipParameters.setCompressionMethod(Zip4jConstants.COMP_STORE);
      if (!Zip4jUtil.isStringNotNullAndNotEmpty(this.zipParameters.getFileNameInZip())) {
        throw new ZipException("file name is empty for external stream");
      if (this.zipParameters.getFileNameInZip().endsWith("/") || 
          this.zipParameters.getFileNameInZip().endsWith("\\")) {
        this.zipParameters.setEncryptFiles(false);
        this.zipParameters.setEncryptionMethod(-1);
        this.zipParameters.setCompressionMethod(Zip4jConstants.COMP_STORE);
    if (this.zipParameters.isEncryptFiles()) {
      initEncrypter();
      if (encrypter != null) {
        if (zipParameters.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_STANDARD) {
          byte[] headerBytes = ((StandardEncrypter)encrypter).getHeaderBytes();
          outputStream.write(headerBytes);

代码示例来源:origin: org.apache.apex/apex-engine

public static void createAppPackageFile(File fileToBeCreated, File directory) throws ZipException
{
 ZipFile zipFile = new ZipFile(fileToBeCreated);
 ZipParameters params = new ZipParameters();
 params.setIncludeRootFolder(false);
 zipFile.addFolder(directory, params);
}

代码示例来源:origin: com.github.axet/zip4j

if ((parameters.getCompressionMethod() != Zip4jConstants.COMP_STORE) && 
    parameters.getCompressionMethod() != Zip4jConstants.COMP_DEFLATE) {
  throw new ZipException("unsupported compression type");
if (parameters.getCompressionMethod() == Zip4jConstants.COMP_DEFLATE) {
  if (parameters.getCompressionLevel() < 0 && parameters.getCompressionLevel() > 9) {
    throw new ZipException("invalid compression level. compression level dor deflate should be in the range of 0-9");
if (parameters.isEncryptFiles()) {
  if (parameters.getEncryptionMethod() != Zip4jConstants.ENC_METHOD_STANDARD && 
      parameters.getEncryptionMethod() != Zip4jConstants.ENC_METHOD_AES) {
    throw new ZipException("unsupported encryption method");
  if (parameters.getPassword() == null || parameters.getPassword().length <= 0) {
    throw new ZipException("input password is empty or null");
  parameters.setAesKeyStrength(-1);
  parameters.setEncryptionMethod(-1);

代码示例来源:origin: com.github.axet/zip4j

ZipParameters fileParameters = (ZipParameters) parameters.clone();
  if (fileParameters.isEncryptFiles() && fileParameters.getEncryptionMethod() == Zip4jConstants.ENC_METHOD_STANDARD) {
    progressMonitor.setCurrentOperation(ProgressMonitor.OPERATION_CALC_CRC);
    fileParameters.setSourceFileCRC((int)CRCUtil.computeFileCRC((NativeStorage)fileList.get(i), progressMonitor));
    progressMonitor.setCurrentOperation(ProgressMonitor.OPERATION_ADD);
    fileParameters.setCompressionMethod(Zip4jConstants.COMP_STORE);

代码示例来源:origin: org.openmrs.maven.plugins/openmrs-sdk-maven-plugin

downloadOWAs(targetDirectory, distroProperties, owasDir);
warfile.addFolder(tempDir, new ZipParameters());
try {
  FileUtils.deleteDirectory(tempDir);

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com