Class CompositeJarContents

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

@Internal public final class CompositeJarContents extends Object implements JarContents
A composite JarContents implementation which combines the contents of other jar contents transparently, and optionally applies filtering.
  • Field Details

  • Constructor Details

  • Method Details

    • 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
    • isFiltered

      public boolean isFiltered()
    • getChecksum

      public Optional<String> getChecksum()
      For a composite jar, we compute the checksum as the SHA-256 of the concatenation of the checksums of the delegates, in order. If the composite jar is filtered, or any delegate does not have a checksum, then the composite jar does not have a checksum.
      Specified by:
      getChecksum in interface JarContents
      Returns:
      SHA-256 hash of the contents, if available
    • computeChecksum

      private Optional<String> computeChecksum()
    • getPrimaryPath

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

      public String toString()
      Overrides:
      toString in class Object
    • 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
    • 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
    • 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
    • close

      public void close() throws IOException
      Specified by:
      close in interface AutoCloseable
      Specified by:
      close in interface Closeable
      Throws:
      IOException
    • isMasked

      private boolean isMasked(int delegateIdx, String relativePath)
      Returns true if the given relative path is hidden by the given delegates filter.
      Returns:
      true if the given relative path is hidden by the given delegates filter
    • getDelegates

      public List<JarContents> getDelegates()