Interface Archive<T extends Archive<T>>
- All Superinterfaces:
Assignable
- All Known Subinterfaces:
EnterpriseArchive, GenericArchive, JavaArchive, ResourceAdapterArchive, WebArchive
Represents a collection of resources which may be constructed programmatically. In effect this represents a virtual
filesystem.
All
Because
All
Archive types support the addition of Nodes under a designated ArchivePath (context). The
contents of a Node are either a directory or Asset.
Archives are generally created via an ArchiveFactory or via the default configuration shortcut
ShrinkWrap utility class.
Because
Archives are Assignable, they may be wrapped in another user "view" used to perform
operations like adding JavaEE Spec-specific resources or exporting in ZIP format.- Version:
- $Revision: $
- Author:
- ALR
-
Method Summary
Modifier and TypeMethodDescriptionadd(Archive<?> archive, String path, Class<? extends StreamExporter> exporter) Add an archive under a specific context and maintain the archive name as context path.add(Archive<?> archive, ArchivePath path, Class<? extends StreamExporter> exporter) Add an archive under a specific context and maintain the archive name as context path.Adds the specified asset under the context denoted by the specified targetAdds the specified asset under the specified target (directory) using the specified name.add(Asset asset, ArchivePath target) Adds the specified asset under the specified path into the target contextadd(Asset asset, ArchivePath target, String name) Adds the specified asset under the specified target (directory) using the specified name.add(NamedAsset namedAsset) Adds the asset encapsulated within the specifiedNamedAssetunder the encapsulated name and target (directory)addAsDirectories(String... paths) Adds the specified directories.addAsDirectories(ArchivePath... paths) Adds the specified directories.addAsDirectory(String path) Adds the specified directory.addAsDirectory(ArchivePath path) Adds the specified directory.addHandlers(ArchiveEventHandler... handlers) Adds an array of handlers for callback-based operations.booleanDenotes whether this archive contains a resource at the specified pathbooleancontains(ArchivePath path) Denotes whether this archive contains a resource at the specified pathdelete(ArchivePath path) filter(Filter<ArchivePath> filter) Obtains all assets matching given filter in this archive as a new Archive.
This is an alias for shallowCopy(Filter).Obtains theNodelocated at the specified pathget(ArchivePath path) Obtains theNodelocated at the specified path<X extends Archive<X>>
XGet a nestedArchiveas a specific type.
The found Archives must have been added as an Archive, no import is performed.<X extends Archive<X>>
XgetAsType(Class<X> type, String path, ArchiveFormat archiveFormat) Get a nestedArchiveas a specific type using the specifiedArchiveFormat<X extends Archive<X>>
XgetAsType(Class<X> type, ArchivePath path) Get a nestedArchiveas a specific type.
The found Archives must have been added as an Archive, no import is performed.<X extends Archive<X>>
XgetAsType(Class<X> type, ArchivePath path, ArchiveFormat archiveFormat) <X extends Archive<X>>
Collection<X> getAsType(Class<X> type, Filter<ArchivePath> filter) Get all nestedArchivematching the filter as a specific type.
The found Archives must have been added as an Archive, no import is performed.<X extends Archive<X>>
Collection<X> getAsType(Class<X> type, Filter<ArchivePath> filter, ArchiveFormat archiveFormat) Get all nestedArchivematching the filter as a specific type using the specifiedArchiveFormat.Obtains all assets in this archive, along with their respective paths.getContent(Filter<ArchivePath> filter) Obtains all assets matching given filter in this archive, along with its respective Path.getId()Obtains a globally-unique identifier for thisArchivegetName()Obtains the name of this archive (i.e.Merge the contents from an existing archive without maintaining the archive name in the context path.Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path.merge(Archive<?> source, String path, Filter<ArchivePath> filter) Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path.merge(Archive<?> source, ArchivePath path) Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path.merge(Archive<?> source, ArchivePath path, Filter<ArchivePath> filter) Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path.merge(Archive<?> source, Filter<ArchivePath> filter) Merge the contents from an existing archive without maintaining the archive name in the context path.Moves the asset under the source path to the target path.move(ArchivePath source, ArchivePath target) Moves the asset under the source path to the target path.Creates a shallow copy of thisArchive.shallowCopy(Filter<ArchivePath> filter) Creates a shallow copy of thisArchivebased on given filter.toString()Acts as a shorthand fortoString(Formatter)where theFormatters.SIMPLEis leveraged.toString(boolean verbose) If "true" is specified, acts as a shorthand fortoString(Formatter)where theFormatters.VERBOSEis leveraged.voidwriteTo(OutputStream outputStream, Formatter formatter) Prints the content of thisArchiveto the specifiedOutputStreamon the format defined by the specifiedFormatter.Methods inherited from interface Assignable
as
-
Method Details
-
getName
String getName()Obtains the name of this archive (i.e. myLibrary.jar)- Returns:
- The name of the archive
-
getId
-
add
Adds the specified asset under the specified path into the target contextIf an asset already exists at the specified path, it will be replaced.
- Parameters:
asset- The asset to addtarget- The context under which to add the asset- Returns:
- This archive
- Throws:
IllegalArgumentException- If no target or asset were specifiedIllegalArchivePathException- If the target is invalid.
-
add
Adds the specified asset under the specified target (directory) using the specified name. The resultant path will treat the specified path as a prefix namespace, then append the name.If an asset already exists at the specified path, it will be replaced.
- Parameters:
asset- The asset to addtarget- The context directory under which to add the assetname- The name to assign the asset under the target namespace- Returns:
- This archive
- Throws:
IllegalArgumentException- If the target, name, or asset was not specifiedIllegalArchivePathException- If the target is invalid.
-
add
Adds the specified asset under the specified target (directory) using the specified name. The resultant path will treat the specified path as a prefix namespace, then append the name.If an asset already exists at the specified path, it will be replaced.
- Parameters:
asset- The asset to addtarget- The context directory under which to add the assetname- The name to assign the asset under the target namespace- Returns:
- This archive
- Throws:
IllegalArgumentException- If the target, name, or asset was not specifiedIllegalArchivePathException- If the target is invalid.
-
add
Adds the asset encapsulated within the specifiedNamedAssetunder the encapsulated name and target (directory)If an asset already exists at the specified path, it will be replaced.
- Parameters:
namedAsset- The named asset to add- Returns:
- This archive
- Throws:
IllegalArgumentException- If either the target or asset is not specifiedIllegalArchivePathException- If the target is invalid.
-
add
Adds the specified asset under the context denoted by the specified targetIf an asset already exists at the specified path, it will be replaced.
- Parameters:
asset- The asset to addtarget- The context under which to add the asset- Returns:
- This archive
- Throws:
IllegalArgumentException- If either the target or asset is not specifiedIllegalArchivePathException- If the target is invalid.
-
addAsDirectory
Adds the specified directory.- Parameters:
path- The path to add- Returns:
- This archive
- Throws:
IllegalArgumentException- If no path was specifiedIllegalArchivePathException- If the path is invalid.
-
addAsDirectories
Adds the specified directories.- Parameters:
paths- The paths to add- Returns:
- This archive
- Throws:
IllegalArgumentException- If no paths were specifiedIllegalArchivePathException- If at least one path is invalid.
-
addAsDirectory
Adds the specified directory.- Parameters:
path- The path to add- Returns:
- This archive
- Throws:
IllegalArgumentException- If no path was specifiedIllegalArchivePathException- If the path is invalid.
-
addAsDirectories
Adds the specified directories.- Parameters:
paths- The paths to add- Returns:
- This archive
- Throws:
IllegalArgumentException- If no paths were specifiedIllegalArchivePathException- If at least one path is invalid.
-
addHandlers
Adds an array of handlers for callback-based operations.- Parameters:
handlers- The handlers to be added for callback- Returns:
- This archive
-
get
Obtains theNodelocated at the specified path- Parameters:
path- The path to the node within the archive- Returns:
- The
Node, or null if nothing is found at the specified path - Throws:
IllegalArgumentException- If the path is not specified
-
get
Obtains theNodelocated at the specified path- Parameters:
path- The path to the node within the archive- Returns:
- The
Node, or null if nothing is found at the Path - Throws:
IllegalArgumentException- If the path is not specified
-
getAsType
Get a nestedArchiveas a specific type.
The found Archives must have been added as an Archive, no import is performed.- Type Parameters:
X- The type of archive- Parameters:
type- The Type to return the Archive aspath- The location of the Archive- Returns:
- The found Archive as given type or null if none found at given path
- Throws:
IllegalArgumentException- if foundAssetis not pointing to aArchive- See Also:
-
getAsType
Get a nestedArchiveas a specific type.
The found Archives must have been added as an Archive, no import is performed.- Type Parameters:
X- The type of archive- Parameters:
type- The Type to return the Archive aspath- The location of the Archive- Returns:
- The found Archive as given type or null if none found at given
ArchivePath - Throws:
IllegalArgumentException- if foundAssetis not pointing to aArchive- See Also:
-
getAsType
Get all nestedArchivematching the filter as a specific type.
The found Archives must have been added as an Archive, no import is performed.- Type Parameters:
X- The type of archive- Parameters:
type- The Type to return the Archive asfilter- Filter to match result- Returns:
- A
Collectionof found Archives matching given filter or emptyCollectionif non found. - Throws:
IllegalArgumentException- if foundAssetis not pointing to aArchive- See Also:
-
getAsType
Get a nestedArchiveas a specific type using the specifiedArchiveFormat- Parameters:
type- The Type to return the Archive aspath- The location of the ArchivearchiveFormat- The archive format- Returns:
- The found Archive as given type or null if none found at the given path
- See Also:
-
getAsType
- Parameters:
type- The Type to return the Archive aspath- The location of the ArchivearchiveFormat- The archive format- Returns:
- The found Archive as given type or null if none found at given
ArchivePath - See Also:
-
getAsType
<X extends Archive<X>> Collection<X> getAsType(Class<X> type, Filter<ArchivePath> filter, ArchiveFormat archiveFormat) Get all nestedArchivematching the filter as a specific type using the specifiedArchiveFormat.- Type Parameters:
X- The type of archive- Parameters:
type- The Type to return the Archive asfilter- Filter to match resultarchiveFormat- The archive format- Returns:
- A
Collectionof found Archives matching given filter or emptyCollectionif non found. - See Also:
-
contains
Denotes whether this archive contains a resource at the specified path- Parameters:
path- The path to the resource- Returns:
- true if the archive contains the resource, false otherwise
- Throws:
IllegalArgumentException- If the path is not specified
-
contains
Denotes whether this archive contains a resource at the specified path- Parameters:
path- The path to the resource- Returns:
- true if the archive contains the resource, false otherwise
- Throws:
IllegalArgumentException- If the path is not specified
-
delete
Removes theNodein theArchiveat the specifiedArchivePath. If the path is a directory, recursively removes all contents. If the path does not exist, return null.- Parameters:
path- The path to the node to be removed- Returns:
- The Node removed
- Throws:
IllegalArgumentException- If the path is not specified
-
delete
Removes theNodein theArchiveat theArchivePathindicated by the specified String archivePath. If the path is a directory, recursively removes all contents. If the path does not exist, return null.- Parameters:
archivePath- The path to the node to be removed- Returns:
- The Node removed
- Throws:
IllegalArgumentException- If the path is not specified- See Also:
-
getContent
Map<ArchivePath, Node> getContent()Obtains all assets in this archive, along with their respective paths. The returned Map will be an immutable view.- Returns:
- A map of all paths and nodes in the archive
-
getContent
Obtains all assets matching given filter in this archive, along with its respective Path. The returned Map will be an immutable view.- Parameters:
filter- Filter to match assets- Returns:
- A map of the paths and nodes found in the archive matching the filter
-
filter
Obtains all assets matching given filter in this archive as a new Archive.
This is an alias for shallowCopy(Filter).- Parameters:
filter- Filter to match assets- Returns:
- A new archive containing the filtered assets
- See Also:
-
add
T add(Archive<?> archive, ArchivePath path, Class<? extends StreamExporter> exporter) throws IllegalArgumentException Add an archive under a specific context and maintain the archive name as context path.- Parameters:
archive- The archive to addpath- The path to useexporter- Exporter type to use in fulfilling theAsset.openStream()contract for the added (nested) archive.- Returns:
- This archive
- Throws:
IllegalArgumentException- If any argument is not specified
-
add
T add(Archive<?> archive, String path, Class<? extends StreamExporter> exporter) throws IllegalArgumentException Add an archive under a specific context and maintain the archive name as context path.- Parameters:
archive- The archive to addpath- The path to useexporter- Exporter type to use in fulfilling theAsset.openStream()contract for the added (nested) archive.- Returns:
- This archive
- Throws:
IllegalArgumentException- If the path or archive are not specified
-
merge
Merge the contents from an existing archive without maintaining the archive name in the context path.- Parameters:
source- Archive to add contents from- Returns:
- This archive
- Throws:
IllegalArgumentException- If the existing archive is not specified
-
merge
Merge the contents from an existing archive without maintaining the archive name in the context path.The filter controls which
ArchivePaths to include from the sourceArchive.- Parameters:
source- Archive to add contents fromfilter- Filter to match paths to be included- Returns:
- This archive
- Throws:
IllegalArgumentException- If the existing archive is not specified
-
merge
Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path.- Parameters:
source- Archive to add contents frompath- Path to add contents to- Returns:
- This archive
- Throws:
IllegalArgumentException- If the path or existing archive is not specified
-
merge
Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path.- Parameters:
source- Archive to add contents frompath- Path to add contents to- Returns:
- This archive
- Throws:
IllegalArgumentException- If the path or existing archive is not specified
-
merge
T merge(Archive<?> source, ArchivePath path, Filter<ArchivePath> filter) throws IllegalArgumentException Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path. The filter controls whichArchivePaths to include from the sourceArchive.- Parameters:
source- Archive to add contents frompath- Path to add contents tofilter- Filter to match paths to be included- Returns:
- This archive
- Throws:
IllegalArgumentException- If the path or existing archive is not specified
-
merge
Merge the contents from an existing archive in a specific path without maintaining the archive name in the context path. The filter controls whichArchivePaths to include from the sourceArchive.- Parameters:
source- Archive to add contents frompath- Path to add contents tofilter- Filter to match paths to be included- Returns:
- This archive
- Throws:
IllegalArgumentException- If the path or existing archive is not specified
-
move
T move(ArchivePath source, ArchivePath target) throws IllegalArgumentException, IllegalArchivePathException Moves the asset under the source path to the target path.- Parameters:
source- The context under which to remove the assetstarget- The context under which to add the moved assets- Returns:
- the resulting archive with the moved assets
- Throws:
IllegalArgumentException- If any of the paths is not specifiedIllegalArchivePathException- If the source path is invalid.
-
move
Moves the asset under the source path to the target path.- Parameters:
source- The context under which to remove the assetstarget- The context under which to add the moved assets- Returns:
- the resulting archive with the moved assets
- Throws:
IllegalArgumentException- If any of the paths is not specifiedIllegalArchivePathException- If the source path is invalid.
-
toString
String toString()Acts as a shorthand fortoString(Formatter)where theFormatters.SIMPLEis leveraged. -
toString
If "true" is specified, acts as a shorthand fortoString(Formatter)where theFormatters.VERBOSEis leveraged. Otherwise, theFormatters.SIMPLEwill be used (equivalent totoString()).- Parameters:
verbose- If true, use the verbose formatter; otherwise use the simple formatter- Returns:
- A string representation of the archive
-
toString
Returns a view of thisArchiveas returned from the specifiedFormatter. Common options may be to use the predefined formatters located inFormatters- Parameters:
formatter- The formatter to use- Returns:
- A string representation of the archive using the specified formatter
- Throws:
IllegalArgumentException- If the formatter is not specified
-
writeTo
Prints the content of thisArchiveto the specifiedOutputStreamon the format defined by the specifiedFormatter. The caller is responsible for opening, flushing and eventually closing the stream.- Parameters:
outputStream- the stream to print the archive contents toformatter- the output format- Throws:
IllegalArgumentException- if an exceptions occur when writing the archive contents.
-
shallowCopy
Creates a shallow copy of thisArchive. Assets from this archive are made available under the same paths. However, removing old assets or adding new assets on this archive affects does not affect the new archive.- Returns:
- a new archive with a copy of the pointers to the assets
-
shallowCopy
Creates a shallow copy of thisArchivebased on given filter. Assets from this archive are made available under the same paths. However, removing old assets or adding new assets on this archive affects does not affect the new archive. This allows for filtering of both directory-based andAsset-based paths.- Returns:
- a new archive with a copy of the pointers to the assets
-