Class ZipEntryHelper
java.lang.Object
org.ametys.plugins.contentio.archive.ZipEntryHelper
Utility class to retrieve
Path
representing folders or files under a ZIP archive.-
Method Summary
Modifier and TypeMethodDescriptionstatic DirectoryStream<Path>
children
(Path zipArchivePath, Optional<String> startingPath, DirectoryStream.Filter<? super Path> filter) Opens a directory, returning aDirectoryStream
to iterate over the entries in the directory.static boolean
zipEntryFileExists
(Path zipPath, String zipEntryFilePath) Checks if the given file entry exists in the ZIP archive.static InputStream
zipEntryFileInputStream
(Path zipPath, String zipEntryFilePath) Returns an input stream for reading the content of an entry file of a ZIP archive.static boolean
zipEntryFolderExists
(Path zipPath, String zipEntryFolderPath) Checks if the given folder entry exists in the ZIP archive.static Path
zipFileRoot
(Path zipArchivePath) Return thePath
of the root of the given ZIP archive.zipFileTree
(Path zipArchivePath, Optional<String> startingPath, BiPredicate<Path, BasicFileAttributes> filter) 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.
-
Method Details
-
zipFileRoot
Return thePath
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 IOExceptionReturns 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 pathstartingPath
- The (optional) starting path within the ZIPfilter
- The filter- Returns:
- the
Stream
ofPath
- 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 aDirectoryStream
to iterate over the entries in the directory.- Parameters:
zipArchivePath
- The zip pathstartingPath
- The (optional) starting path within the ZIPfilter
- 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 pathzipEntryFolderPath
- 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
Checks if the given file entry exists in the ZIP archive.- Parameters:
zipPath
- The zip pathzipEntryFilePath
- 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 withzipEntryFileExists(java.nio.file.Path, java.lang.String)
, otherwise you may get anIOException
.
It must be closed.- Parameters:
zipPath
- The zip pathzipEntryFilePath
- The path within the ZIP- Returns:
- a new input stream
- Throws:
IOException
- if an I/O error is thrown when accessing a file.
-