Class Bundle

java.lang.Object
htsjdk.beta.io.bundle.Bundle
All Implemented Interfaces:
Serializable, Iterable<BundleResource>
Direct Known Subclasses:
ReadsBundle

public class Bundle extends Object implements Iterable<BundleResource>, Serializable
An immutable collection of related resources (a primary resource, such as "reads", "variants", "features", or "reference"), plus zero or more related companion resources ("index", "dictionary", "MD5", etc.).

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.

See Also:
  • Constructor Details

    • Bundle

      public Bundle(String primaryContentType, Collection<BundleResource> resources)
      Create a new bundle from an existing resource collection.
      Parameters:
      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 resources
      resources - resources to include in this bundle, may not be null or empty
  • Method Details

    • get

      public Optional<BundleResource> get(String targetContentType)
      Get the BundleResource for the provided targetContentType string.
      Parameters:
      targetContentType - the content type to be retrieved from the bundle
      Returns:
      an Optional that contains the targetContent type
    • getOrThrow

      public BundleResource getOrThrow(String requiredContentType)
      Get the BundleResource for the provided targetContentType string, or throw if no such resource exists.
      Parameters:
      requiredContentType - the content type to be retrieved from the bundle
      Returns:
      a BundleResource of type targetContentType
      Throws:
      IllegalArgumentException - if the targetContentType resource isn't present in the bundle
    • getPrimaryContentType

      public String getPrimaryContentType()
      Get the primary content type for this bundle.
      Returns:
      the primary content type for this bundle
    • getPrimaryResource

      public BundleResource getPrimaryResource()
      Get the primary BundleResource for this bundle.
      Returns:
      the primary BundleResource for this bundle.
    • getResources

      public Collection<BundleResource> getResources()
      Get the collection of resources from this Bundle.
    • iterator

      public Iterator<BundleResource> iterator()
      Get an iterator of BundleResources for this bundle.
      Specified by:
      iterator in interface Iterable<BundleResource>
      Returns:
      iterator of BundleResources for this bundle.
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object