Class ZipEntryHelper

java.lang.Object
org.ametys.plugins.contentio.archive.ZipEntryHelper

public final class ZipEntryHelper extends Object
Utility class to retrieve Path representing folders or files under a ZIP archive.
  • Method Details

    • zipFileRoot

      public static Path zipFileRoot(Path zipArchivePath) throws IOException
      Return the Path of the root of the given ZIP archive.
      Parameters:
      zipArchivePath - The zip path
      Returns:
      the PAth of the root
      Throws:
      IOException - if an I/O error is thrown when accessing a file.
    • zipFileTree

      public static Stream<Path> zipFileTree(Path zipArchivePath, Optional<String> startingPath, BiPredicate<Path,BasicFileAttributes> filter) throws IOException
      Returns a Stream that is lazily populated with Path by searching for files in a file tree rooted at a given starting path within the ZIP, or the ZIP root.
      Parameters:
      zipArchivePath - The zip path
      startingPath - The (optional) starting path within the ZIP
      filter - The filter
      Returns:
      the Stream of Path
      Throws:
      IOException - if an I/O error is thrown when accessing a file.
    • children

      public static DirectoryStream<Path> children(Path zipArchivePath, Optional<String> startingPath, DirectoryStream.Filter<? super Path> filter) throws IOException
      Opens a directory, returning a DirectoryStream to iterate over the entries in the directory.
      Parameters:
      zipArchivePath - The zip path
      startingPath - The (optional) starting path within the ZIP
      filter - The filter
      Returns:
      a new and opened DirectoryStream object
      Throws:
      IOException - if an I/O error is thrown when accessing a file.
    • zipEntryFolderExists

      public static boolean zipEntryFolderExists(Path zipPath, String zipEntryFolderPath) throws IOException
      Checks if the given folder entry exists in the ZIP archive.
      Parameters:
      zipPath - The zip path
      zipEntryFolderPath - The path of the folder within the ZIP
      Returns:
      true if the entry exists
      Throws:
      IOException - if an I/O error is thrown when accessing a file.
    • zipEntryFileExists

      public static boolean zipEntryFileExists(Path zipPath, String zipEntryFilePath) throws IOException
      Checks if the given file entry exists in the ZIP archive.
      Parameters:
      zipPath - The zip path
      zipEntryFilePath - The path of the file within the ZIP
      Returns:
      true if the entry exists
      Throws:
      IOException - if an I/O error is thrown when accessing a file.
    • zipEntryFileInputStream

      public static InputStream zipEntryFileInputStream(Path zipPath, String zipEntryFilePath) throws IOException
      Returns an input stream for reading the content of an entry file of a ZIP archive.
      You may check if the entry exist with zipEntryFileExists(java.nio.file.Path, java.lang.String), otherwise you may get an IOException.
      It must be closed.
      Parameters:
      zipPath - The zip path
      zipEntryFilePath - The path within the ZIP
      Returns:
      a new input stream
      Throws:
      IOException - if an I/O error is thrown when accessing a file.