Class ManifestFile
Wraps a Manifest so callers can read main-attribute and per-section entries via an
Optional-returning API without depending on the marshalling stack.
Example:
Notes:
- This class is immutable and thread-safe once constructed.
-
Constructor Summary
ConstructorsConstructorDescriptionManifestFile(File f) Loads a manifest from a file on disk.Loads a manifest from an input stream.Loads a manifest from a reader.ManifestFile(Class<?> c) Loads the manifest of the jar containing the given class.ManifestFile(Path path) Loads a manifest from a path.ManifestFile(Manifest mf) Wraps an existingManifest. -
Method Summary
Modifier and TypeMethodDescriptionasMap()Returns the main attributes as an unmodifiable map.Returns the attributes of the named section as an unmodifiable map.Returns the value of a main-attribute key.Returns the value of a key inside the named section.sections()Returns the names of all per-entry sections in the manifest.toString()
-
Constructor Details
-
ManifestFile
Loads the manifest of the jar containing the given class.If the class isn't packaged inside a Jar (e.g. running from an exploded classpath), the resulting instance has no main attributes and no sections.
- Parameters:
c- The anchor class. Must not benull .- Throws:
IOException- If the manifest could not be read.
-
ManifestFile
Loads a manifest from a file on disk.- Parameters:
f- The manifest file. Must not benull .- Throws:
IOException- If the manifest could not be read.
-
ManifestFile
Loads a manifest from an input stream.The stream must end in a newline to pick up the last line.
- Parameters:
in- The manifest stream. Must not benull .- Throws:
IOException- If the manifest could not be read.
-
ManifestFile
Wraps an existingManifest.- Parameters:
mf- The manifest. Can benull , in which case the manifest is treated as having no attributes or sections.
-
ManifestFile
Loads a manifest from a path.- Parameters:
path- The manifest path. Must not benull .- Throws:
IOException- If the manifest could not be read.
-
ManifestFile
Loads a manifest from a reader.The reader's contents must end in a newline to pick up the last line.
- Parameters:
r- The manifest reader. Must not benull .- Throws:
IOException- If the manifest could not be read.
-
-
Method Details
-
get
Returns the value of a main-attribute key.- Parameters:
key- The main-attribute key. Can benull , in which case an empty value is returned.- Returns:
- The value, or empty if the key is unset.
-
get
Returns the value of a key inside the named section.- Parameters:
section- The section name. Can benull , in which case an empty value is returned.key- The attribute key. Can benull , in which case an empty value is returned.- Returns:
- The value, or empty if the section or key is unset.
-
sections
Returns the names of all per-entry sections in the manifest.- Returns:
- An unmodifiable set of section names.
-
asMap
Returns the main attributes as an unmodifiable map.- Returns:
- The main-attribute map.
-
asMap
Returns the attributes of the named section as an unmodifiable map.- Parameters:
section- The section name. Can benull , in which case an empty map is returned.- Returns:
- The section's attribute map, or an empty map if the section is unknown.
-
toString
-