Class FolderJarContents

java.lang.Object
net.neoforged.fml.jarcontents.FolderJarContents
All Implemented Interfaces:
Closeable, AutoCloseable, JarContents

@Internal public final class FolderJarContents extends Object implements JarContents
  • Field Details

    • path

      private final Path path
    • manifestLock

      private final Object manifestLock
    • cachedManifest

      private Manifest cachedManifest
  • Constructor Details

    • FolderJarContents

      public FolderJarContents(Path path)
  • Method Details

    • getPrimaryPath

      public Path getPrimaryPath()
      Specified by:
      getPrimaryPath in interface JarContents
    • getChecksum

      public Optional<String> getChecksum()
      Description copied from interface: JarContents
      Returns SHA-256 hash of the contents, if available.

      This value is intended to be used as a cache-key, and will be empty if the jar contents are not stable enough to be cached (i.e. they're sourced from memory or a folder).

      Specified by:
      getChecksum in interface JarContents
      Returns:
      SHA-256 hash of the contents, if available
    • get

      @Nullable public @Nullable JarResource get(String relativePath)
      Description copied from interface: JarContents
      Tries to find a resource with the given path in this jar content.
      Specified by:
      get in interface JarContents
      Parameters:
      relativePath - See JarContents for a definition of relative paths.
      Returns:
      Null if the resource could not be found within the jar, or if relativePath refers to a directory.
    • containsFile

      public boolean containsFile(String relativePath)
      Description copied from interface: JarContents
      Checks, if a given file exists in this jar.
      Specified by:
      containsFile in interface JarContents
      Parameters:
      relativePath - The path to the file, relative to the root of this Jar file.
      Returns:
      True if the file exists, false if it doesn't or relativePath refers to a directory.
    • openFile

      public InputStream openFile(String relativePath) throws IOException
      Description copied from interface: JarContents
      Tries to open a file inside the jar content using a path relative to the root.

      The stream will not be buffered.

      The behavior when relativePath refers to a directory rather than a file is unspecified. The method may throw a IOException immediately, but may also defer this until the first byte is read from the stream. This behavior is filesystem provider specific.

      Specified by:
      openFile in interface JarContents
      Returns:
      null if the file cannot be found
      Throws:
      IOException
    • readFile

      public byte[] readFile(String relativePath) throws IOException
      Description copied from interface: JarContents
      A convenience method that opens a file and if the file was found, returns its content.

      Trying to read the contents of a directory using this method will throw an IOException.

      Specified by:
      readFile in interface JarContents
      Returns:
      Null if the file does not exist.
      Throws:
      IOException
    • getContentRoots

      public Collection<Path> getContentRoots()
      Description copied from interface: JarContents
      Returns the locations that this Jar content was opened from.

      Usually this will only contain a single path, for example to the Jar file that was opened, but especially during development, it can contain multiple build output folders that were joined into a single virtual Jar file.

      The resulting paths do not need to be on the local file-system, they can be from custom NIO filesystem implementations.

      The returned list may also not contain all content roots if the underlying jar content is held in-memory.

      Specified by:
      getContentRoots in interface JarContents
    • visitContent

      public void visitContent(String startingFolder, JarResourceVisitor visitor)
      Description copied from interface: JarContents
      Visits all content found in this jar, starting in the given folder.

      If the folder does not exist, the visitor is not invoked and no error is raised.

      Specified by:
      visitContent in interface JarContents
    • getVisitStartingPoint

      private Path getVisitStartingPoint(String startingFolder)
    • findFile

      public Optional<URI> findFile(String relativePath)
      Description copied from interface: JarContents
      Looks for a file in the jar.
      Specified by:
      findFile in interface JarContents
      Returns:
      A URI for the file, or empty if the file cannot be found or if relativePath refers to a directory.
    • getManifest

      public Manifest getManifest()
      Description copied from interface: JarContents
      Returns the manifest of the jar. Empty if no manifest is present in the jar.

      NOTE: Do not modify the returned manifest.

      Specified by:
      getManifest in interface JarContents
      Returns:
      the manifest of the jar
    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • fromRelativePath

      private Path fromRelativePath(String relativePath)