Class ZipFileAccess
java.lang.Object
dev.jcputney.elearning.parser.api.AbstractArchiveFileAccess
dev.jcputney.elearning.parser.impl.access.ZipFileAccess
- All Implemented Interfaces:
FileAccess,AutoCloseable
An implementation of the
FileAccess interface for
accessing files within a ZIP archive. This class allows file existence checks, file listing, and
retrieving file contents from a ZIP file.-
Field Summary
Fields inherited from class dev.jcputney.elearning.parser.api.AbstractArchiveFileAccess
rootPath -
Constructor Summary
ConstructorsConstructorDescriptionZipFileAccess(String zipFilePath) Constructs a newZipFileAccessinstance for the specified ZIP path. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()Closes the ZIP file to release resources.booleanfileExistsInternal(String path) Checks if a file exists within the ZIP archive.Retrieves the contents of a file within the ZIP archive as an InputStream.getFileContentsInternal(String path, StreamingProgressListener progressListener) Retrieves the contents of a file within the ZIP archive as an InputStream with optional progress tracking.Provides all file paths from storage for root path detection.longGets the total size of all files in the ZIP archive.listFilesInternal(String directoryPath) Lists all files within a specified directory in the ZIP archive.Methods inherited from class dev.jcputney.elearning.parser.api.AbstractArchiveFileAccess
checkForRootPath, detectRootPath, getRootPath, initializeRootPath, normalizeDirectory, stripRootPathMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface dev.jcputney.elearning.parser.api.FileAccess
clearCaches, fileExists, fileExistsBatch, fullPath, getAllFiles, getFileContents, listFiles, prefetchCommonFiles
-
Constructor Details
-
ZipFileAccess
Constructs a newZipFileAccessinstance for the specified ZIP path.- Parameters:
zipFilePath- The path to the ZIP file.- Throws:
IOException- If the ZIP file can't be opened.
-
-
Method Details
-
fileExistsInternal
Checks if a file exists within the ZIP archive.- Parameters:
path- The path to check (guaranteed to be non-null).- Returns:
- True if the file exists in the ZIP archive, false otherwise.
-
listFilesInternal
Lists all files within a specified directory in the ZIP archive.- Parameters:
directoryPath- The directory to list files from, for example, "folder/" (guaranteed to be non-null).- Returns:
- A list of file paths within the directory, relative to the root path.
-
getFileContentsInternal
Retrieves the contents of a file within the ZIP archive as an InputStream.- Parameters:
path- The path to retrieve contents from (guaranteed to be non-null).- Returns:
- An InputStream of the file contents.
- Throws:
IOException- if the file can't be read.
-
getFileContentsInternal
public InputStream getFileContentsInternal(String path, StreamingProgressListener progressListener) throws IOException Retrieves the contents of a file within the ZIP archive as an InputStream with optional progress tracking.- Parameters:
path- The path to retrieve contents from (guaranteed to be non-null).progressListener- Optional progress listener for tracking large file operations.- Returns:
- An InputStream of the file contents.
- Throws:
IOException- if the file can't be read.
-
close
Closes the ZIP file to release resources.- Specified by:
closein interfaceAutoCloseable- Overrides:
closein classAbstractArchiveFileAccess- Throws:
IOException- if an error occurs while closing the ZIP file.
-
getTotalSize
Gets the total size of all files in the ZIP archive.This method iterates through all entries in the ZIP and sums their uncompressed sizes.
- Returns:
- Total size of all files in bytes (uncompressed)
- Throws:
IOException- if there's an error accessing the ZIP file
-
getStorageFilePaths
Provides all file paths from storage for root path detection.- Specified by:
getStorageFilePathsin classAbstractArchiveFileAccess- Returns:
- An iterable of all file paths in storage format
-