public class Bundle extends java.lang.Object implements java.lang.Iterable<BundleResource>, java.io.Serializable
Each resource in a Bundle is represented by a BundleResource, which in turn describes
a binding mechanism for that resource (such as an IOPath in the case of a URI, Path or file
name; or an input or output stream), and a "content type" string that is unique within that
Bundle. Any string can be used as a content type. Predefined content type strings are defined
in BundleResourceType.
A Bundle must have one resource that is designated as the "primary" resource, specified
by a content type string. A resource with "primary content type" is is guaranteed to be present in
the Bundle.
Since each resource in a Bundle has a content type that is unique within that Bundle,
a Bundle can not be used to represent a list of similar items where each item is equivalent to
each other item (i.e., a list of shards, where each shard in the list is equivalent to each other
shard). Rather Bundles are used to represent related resources where each resource has a unique
character or role relative to the other resources (i.e., a "reads" resource and a corresponding "index"
resource).
Bundles that contain only serializable (IOPathResource) resources may be serialized to, and
deserialized from JSON.
| Constructor and Description |
|---|
Bundle(java.lang.String primaryContentType,
java.util.Collection<BundleResource> resources)
Create a new bundle from an existing resource collection.
|
| Modifier and Type | Method and Description |
|---|---|
boolean |
equals(java.lang.Object o) |
java.util.Optional<BundleResource> |
get(java.lang.String targetContentType)
Get the BundleResource for the provided targetContentType string.
|
BundleResource |
getOrThrow(java.lang.String requiredContentType)
Get the BundleResource for the provided targetContentType string, or throw if
no such resource exists.
|
java.lang.String |
getPrimaryContentType()
Get the primary content type for this bundle.
|
BundleResource |
getPrimaryResource()
Get the primary
BundleResource for this bundle. |
java.util.Collection<BundleResource> |
getResources()
Get the collection of resources from this
Bundle. |
int |
hashCode() |
java.util.Iterator<BundleResource> |
iterator()
Get an iterator of BundleResources for this bundle.
|
java.lang.String |
toString() |
public Bundle(java.lang.String primaryContentType,
java.util.Collection<BundleResource> resources)
primaryContentType - the content type of the primary resource in this bundle. may not be null.
a resource with this content type must be included in resourcesresources - resources to include in this bundle, may not be null or emptypublic java.util.Optional<BundleResource> get(java.lang.String targetContentType)
targetContentType - the content type to be retrieved from the bundlepublic BundleResource getOrThrow(java.lang.String requiredContentType)
requiredContentType - the content type to be retrieved from the bundlejava.lang.IllegalArgumentException - if the targetContentType resource isn't present in the bundlepublic java.lang.String getPrimaryContentType()
public BundleResource getPrimaryResource()
BundleResource for this bundle.BundleResource for this bundle.public java.util.Collection<BundleResource> getResources()
Bundle.public java.util.Iterator<BundleResource> iterator()
iterator in interface java.lang.Iterable<BundleResource>public boolean equals(java.lang.Object o)
equals in class java.lang.Objectpublic int hashCode()
hashCode in class java.lang.Objectpublic java.lang.String toString()
toString in class java.lang.Object