Class CompositeJarContents
- All Implemented Interfaces:
Closeable,AutoCloseable,JarContents
JarContents implementation which combines the contents of other jar contents transparently,
and optionally applies filtering.-
Nested Class Summary
Nested classes/interfaces inherited from interface net.neoforged.fml.jarcontents.JarContents
JarContents.FilteredPath, JarContents.PathFilter -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final JarContents[]private final @Nullable JarContents.PathFilter @Nullable [] -
Constructor Summary
ConstructorsConstructorDescriptionCompositeJarContents(List<JarContents> delegates) Constructs a new composite jar contents without filtering.CompositeJarContents(List<JarContents> delegates, @Nullable List<@Nullable JarContents.PathFilter> filters) Constructs a composite jar contents object with optional filtering. -
Method Summary
Modifier and TypeMethodDescriptionvoidclose()booleancontainsFile(String relativePath) Checks, if a given file exists in this jar.Looks for a file in the jar.@Nullable JarResourceTries to find a resource with the given path in this jar content.For a composite jar, we compute the checksum as the SHA-256 of the concatenation of the checksums of the delegates, in order.Returns the locations that this Jar content was opened from.Returns the manifest of the jar.booleanprivate booleanReturnstrueif the given relative path is hidden by the given delegates filter.Tries to open a file inside the jar content using a path relative to the root.byte[]A convenience method that opens a file and if the file was found, returns its content.toString()voidvisitContent(String startingFolder, JarResourceVisitor visitor) Visits all content found in this jar, starting in the given folder.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface net.neoforged.fml.jarcontents.JarContents
visitContent
-
Field Details
-
delegates
-
filters
-
contentRoots
-
checksum
-
-
Constructor Details
-
CompositeJarContents
Constructs a new composite jar contents without filtering.- See Also:
-
CompositeJarContents
public CompositeJarContents(List<JarContents> delegates, @Nullable @Nullable List<@Nullable JarContents.PathFilter> filters) Constructs a composite jar contents object with optional filtering.- Parameters:
delegates- The delegates that are combined. The delegation is last to first, which means the content in later delegates takes priority.filters- Optional filters for each entry indelegates. Ifnull, no filtering is applied at all. If the filter for a delegate isnull, no filtering is applied to that delegate.- See Also:
-
-
Method Details
-
getContentRoots
Description copied from interface:JarContentsReturns 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:
getContentRootsin interfaceJarContents
-
isFiltered
public boolean isFiltered() -
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:
getChecksumin interfaceJarContents- Returns:
- SHA-256 hash of the contents, if available
-
computeChecksum
-
getPrimaryPath
- Specified by:
getPrimaryPathin interfaceJarContents
-
toString
-
findFile
Description copied from interface:JarContentsLooks for a file in the jar.- Specified by:
findFilein interfaceJarContents- Returns:
- A URI for the file, or empty if the file cannot be found or if
relativePathrefers to a directory.
-
getManifest
Description copied from interface:JarContentsReturns the manifest of the jar. Empty if no manifest is present in the jar.NOTE: Do not modify the returned manifest.
- Specified by:
getManifestin interfaceJarContents- Returns:
- the manifest of the jar
-
get
Description copied from interface:JarContentsTries to find a resource with the given path in this jar content.- Specified by:
getin interfaceJarContents- Parameters:
relativePath- SeeJarContentsfor a definition of relative paths.- Returns:
- Null if the resource could not be found within the jar, or if
relativePathrefers to a directory.
-
containsFile
Description copied from interface:JarContentsChecks, if a given file exists in this jar.- Specified by:
containsFilein interfaceJarContents- 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
relativePathrefers to a directory.
-
openFile
Description copied from interface:JarContentsTries to open a file inside the jar content using a path relative to the root.The stream will not be buffered.
The behavior when
relativePathrefers to a directory rather than a file is unspecified. The method may throw aIOExceptionimmediately, but may also defer this until the first byte is read from the stream. This behavior is filesystem provider specific.- Specified by:
openFilein interfaceJarContents- Returns:
- null if the file cannot be found
- Throws:
IOException
-
readFile
Description copied from interface:JarContentsA 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:
readFilein interfaceJarContents- Returns:
- Null if the file does not exist.
- Throws:
IOException
-
visitContent
Description copied from interface:JarContentsVisits 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:
visitContentin interfaceJarContents
-
close
- Specified by:
closein interfaceAutoCloseable- Specified by:
closein interfaceCloseable- Throws:
IOException
-
isMasked
Returnstrueif the given relative path is hidden by the given delegates filter.- Returns:
trueif the given relative path is hidden by the given delegates filter
-
getDelegates
-