Class Zip


  • public class Zip
    extends Object
    • Method Detail

      • getFile

        public File getFile()
      • sanitize

        public Path sanitize​(@Nonnull
                             Path entry)
        Protection against malicious zip entries that could contain .. path elements or possibly an absolute path. An absolute path is turned relative by discarding the root element. Then the path is normalized (discard . and resolve .. path elements). Finally, all occurrences of .. path elements are merely discarded.
        Parameters:
        entry - a path
        Returns:
        a sanitized version of the given path
      • entries

        public List<String> entries​(String pattern)
                             throws IOException
        returns entry names of zip, matching given pattern if provided
        Parameters:
        pattern - a Java regular expression as a string
        Returns:
        the list of entries matching the given pattern
        Throws:
        IOException - the zip archive could not be correctly unzipped
      • entries

        public List<String> entries()
                             throws IOException
        syntactic sugar for all entries (entries(null))
        Returns:
        all zip entries as a list
        Throws:
        IOException - the zip archive could not be correctly unzipped
      • basedir

        public String basedir()
                       throws IOException
        Returns:
        the first entry name if directory, or empty string otherwise
        Throws:
        IOException - the zip archive could not be correctly unzipped
      • extractTo

        public Zip extractTo​(File dir)
                      throws IOException
        unzips to directory
        Parameters:
        dir - the target directory
        Returns:
        this Zip object
        Throws:
        IOException - the zip archive could not be correctly unzipped
      • delete

        public Zip delete()