Class ResourceUtils

java.lang.Object
dev.jcputney.elearning.parser.util.ResourceUtils

public final class ResourceUtils extends Object
Utility class for managing resources safely, ensuring proper cleanup of ZipFileAccess and other AutoCloseable resources.
  • Method Details

    • parseZipModule

      public static <M extends PackageManifest> ModuleMetadata<M> parseZipModule(String zipPath, Function<FileAccess,ModuleParser<M>> parserFactory) throws ModuleParsingException, IOException
      Parses a module from a ZIP file path, ensuring the ZipFileAccess is properly closed.
      Type Parameters:
      M - The type of package manifest
      Parameters:
      zipPath - Path to the ZIP file
      parserFactory - Function to create a parser from FileAccess
      Returns:
      The parsed module metadata
      Throws:
      ModuleParsingException - if parsing fails
      IOException - if file access fails
    • safeRead

      public static <T> T safeRead(InputStream stream, ResourceUtils.StreamReader<T> reader) throws IOException
      Safely reads content from an InputStream, ensuring it's closed properly.
      Type Parameters:
      T - The return type
      Parameters:
      stream - The input stream to read
      reader - Function to process the stream
      Returns:
      The result of the reader function
      Throws:
      IOException - if reading fails
    • closeIfCloseable

      public static void closeIfCloseable(FileAccess fileAccess)
      Ensures a FileAccess instance is properly closed if it's AutoCloseable. This is useful for conditional cleanup when the FileAccess type is unknown.
      Parameters:
      fileAccess - The FileAccess instance to potentially close