Package net.lingala.zip4j.core

Examples of net.lingala.zip4j.core.ZipFile


        }
    }

    @Override
    public String guessDocumentIRIFromPackage(File file) throws IOException, ZipException {
        ZipFile zipped = new ZipFile(file);
        if (zipped.isValidZipFile()) {
            File tempDir = Files.createTempDir();
            try {
                LOGGER.info("Extracting: %s to %s", file.getAbsoluteFile(), tempDir.getAbsolutePath());
                zipped.extractAll(tempDir.getAbsolutePath());

                File owlFile = findOwlFile(tempDir);
                return guessDocumentIRIFromFile(owlFile);
            } finally {
                FileUtils.deleteDirectory(tempDir);
View Full Code Here


        return null;
    }

    @Override
    public void writePackage(File file, IRI documentIRI, Authorizations authorizations) throws Exception {
        ZipFile zipped = new ZipFile(file);
        if (zipped.isValidZipFile()) {
            File tempDir = Files.createTempDir();
            try {
                LOGGER.info("Extracting: %s to %s", file.getAbsoluteFile(), tempDir.getAbsolutePath());
                zipped.extractAll(tempDir.getAbsolutePath());

                File owlFile = findOwlFile(tempDir);
                importFile(owlFile, documentIRI, authorizations);
            } finally {
                FileUtils.deleteDirectory(tempDir);
View Full Code Here

        LOGGER.log(Level.FINE, message);
        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() + "\"");
      FileInputStream fis = new FileInputStream(file);
View Full Code Here

        LOGGER.log(Level.FINE, message);
        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;
    }

    catch (URISyntaxException e)
View Full Code Here

        LOGGER.log(Level.FINE, message);
        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;
    }

    catch (ZipException e)
View Full Code Here

        attachArtifactsToProject(packagedApplication, dist);
    }

    private void packageAdditionalFiles(List<String> additionalFiles, File distributionFile) throws MojoExecutionException {
        try {
            ZipFile zipFile = new ZipFile(distributionFile);

            ArrayList<File> filesToAdd = new ArrayList<File>(additionalFiles.size());
            for (String file : additionalFiles) {
                File fileToAdd = new File(file);
                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);

                zipFile.addFiles(filesToAdd, parameters);
            }
        } catch (ZipException e) {
            throw new MojoExecutionException("Cannot add files to zipfile: " + distributionFile, e);
        } catch (IOException e) {
            throw new MojoExecutionException("Cannot add files to zipfile: " + distributionFile, e);
View Full Code Here

    }

    @Override
    protected File process(File input) throws Exception {
        try {
            ZipFile zipFile = new ZipFile(input);
            zipFile.extractAll(dest.getAbsolutePath());
        } catch (ZipException e) {
            throw new ExecutionException(e, "Unable to unzip {0} to {1}", input, dest);
        }
        return dest;
    }
View Full Code Here

TOP

Related Classes of net.lingala.zip4j.core.ZipFile

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.