Package net.lingala.zip4j.model

Examples of net.lingala.zip4j.model.ZipParameters


        throw new InternalServerErrorException(message);
      }

      // Add the reference file to the zip file.
      ZipFile zipFile = new ZipFile(file);
      ZipParameters parameters = new ZipParameters();
      parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
      parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);
      zipFile.addFile(refFile, parameters);

      httpHeaders.add("Content-Type", "application/zip");
      httpHeaders.add("Content-Disposition",
        "attachment; filename=\"" + file.getName() + "\"");
View Full Code Here


        throw new IOException(message);
      }

      // Set up the zip file.
      ZipFile zipFile = new ZipFile(file);
      ZipParameters parameters = new ZipParameters();
      parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
      parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);

      // Add all of the product's references to the zip file.
      // Assumes that for hierarchical products, the first reference is the root
      // directory and all of its contents are included in the product.
      List<Reference> references = resource.getProductReferences();
      Reference rootReference = references.get(0);
      File rootFile = new File(new URI(rootReference.getDataStoreReference()));
      if (rootFile.isDirectory())
      {
        // Add the directory and all of its contents.
        zipFile.addFolder(rootFile, parameters);
      }
      else
      {
        // Add each file in the list of references.
        for (Reference reference : references)
        {
          zipFile.addFile(new File(new URI(reference.getDataStoreReference())),
            parameters);
        }
      }

      // Add the product's metadata to the zip file.
      MetadataResource metadataResource = resource.getMetadataResource();
      Metadata metadata = metadataResource.getMetadata();

      ByteArrayOutputStream os = new ByteArrayOutputStream();
      SerializableMetadata serMetadata = new SerializableMetadata(metadata);
      serMetadata.writeMetadataToXmlStream(os);
      ByteArrayInputStream bis = new ByteArrayInputStream(os.toByteArray());

      parameters.setFileNameInZip(resource.getProductName() + ".met");
      parameters.setSourceExternalStream(true);
      zipFile.addStream(bis, parameters);

      return file;
    }
View Full Code Here

        throw new IOException(message);
      }

      // Set up the zip file for the dataset.
      ZipFile zipFile = new ZipFile(file);
      ZipParameters parameters = new ZipParameters();
      parameters.setCompressionMethod(Zip4jConstants.COMP_DEFLATE);
      parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_NORMAL);

      // Create zip archives for each product and add them to the dataset zip.
      for (ProductResource productResource : resource.getProductResources())
      {
        File refFile = productZipper.createZipFile(productResource);
        zipFile.addFile(refFile, parameters);
        if (refFile.exists() && !refFile.delete())
        {
          String message = "Unable to delete a temporary product zip ("
            + refFile.getAbsolutePath()
            + ") after adding it to the dataset zip.";
          LOGGER.log(Level.FINE, message);
          throw new IOException(message);
        }
      }

      // Add the dataset's metadata to the zip.
      MetadataResource metadataResource = resource.getMetadataResource();
      Metadata metadata = metadataResource.getMetadata();

      ByteArrayOutputStream os = new ByteArrayOutputStream();
      SerializableMetadata serMetadata = new SerializableMetadata(metadata);
      serMetadata.writeMetadataToXmlStream(os);
      ByteArrayInputStream bis = new ByteArrayInputStream(os.toByteArray());

      parameters.setFileNameInZip(resource.getName() + ".met");
      parameters.setSourceExternalStream(true);
      zipFile.addStream(bis, parameters);

      return file;
    }
View Full Code Here

                if (!fileToAdd.exists()) {
                    throw new MojoExecutionException(fileToAdd.getCanonicalPath() + " not found, can't add to package");
                }
                filesToAdd.add(fileToAdd);

                ZipParameters parameters = new ZipParameters();
                parameters.setCompressionLevel(Zip4jConstants.DEFLATE_LEVEL_FASTEST);
                parameters.setIncludeRootFolder(true);
                // Let's safely assume that the zip filename is also the root directory all files are packaged in
                parameters.setRootFolderInZip(StringUtils.substringBeforeLast(distributionFile.getName(), ".zip"));
                parameters.setReadHiddenFiles(true);

                String message = String.format("Adding files to distribution zip [%s]: \n\t%s",
                        distributionFile.getCanonicalPath(), StringUtils.join(additionalFiles, "\n\t"));
                getLog().info(message);
View Full Code Here

TOP

Related Classes of net.lingala.zip4j.model.ZipParameters

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.