Class TzdbZoneRulesProvider


  • public final class TzdbZoneRulesProvider
    extends ZoneRulesProvider
    Loads time-zone rules for 'TZDB'.

    This class is public for the service loader to access.

    Specification for implementors

    This class is immutable and thread-safe.
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      (package private) static class  TzdbZoneRulesProvider.Version
      A version of the TZDB rules.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.Set<java.lang.String> loadedUrls
      All the URLs that have been loaded.
      private java.util.List<java.lang.String> regionIds
      All the regions that are available.
      private java.util.concurrent.ConcurrentNavigableMap<java.lang.String,​TzdbZoneRulesProvider.Version> versions
      All the versions that are available.
    • Field Detail

      • regionIds

        private java.util.List<java.lang.String> regionIds
        All the regions that are available.
      • versions

        private final java.util.concurrent.ConcurrentNavigableMap<java.lang.String,​TzdbZoneRulesProvider.Version> versions
        All the versions that are available.
      • loadedUrls

        private java.util.Set<java.lang.String> loadedUrls
        All the URLs that have been loaded. Uses String to avoid equals() on URL.
    • Constructor Detail

      • TzdbZoneRulesProvider

        public TzdbZoneRulesProvider()
        Creates an instance. Created by the ServiceLoader.
        Throws:
        ZoneRulesException - if unable to load
      • TzdbZoneRulesProvider

        public TzdbZoneRulesProvider​(java.net.URL url)
        Creates an instance and loads the specified URL.

        This could be used to wrap this provider in another instance.

        Parameters:
        url - the URL to load, not null
        Throws:
        ZoneRulesException - if unable to load
      • TzdbZoneRulesProvider

        public TzdbZoneRulesProvider​(java.io.InputStream stream)
        Creates an instance and loads the specified input stream.

        This could be used to wrap this provider in another instance.

        Parameters:
        stream - the stream to load, not null, not closed after use
        Throws:
        ZoneRulesException - if unable to load
    • Method Detail

      • provideZoneIds

        protected java.util.Set<java.lang.String> provideZoneIds()
        Description copied from class: ZoneRulesProvider
        SPI method to get the available zone IDs.

        This obtains the IDs that this ZoneRulesProvider provides. A provider should provide data for at least one region.

        The returned regions remain available and valid for the lifetime of the application. A dynamic provider may increase the set of regions as more data becomes available.

        Specified by:
        provideZoneIds in class ZoneRulesProvider
        Returns:
        the unmodifiable set of region IDs being provided, not null
      • provideRules

        protected ZoneRules provideRules​(java.lang.String zoneId,
                                         boolean forCaching)
        Description copied from class: ZoneRulesProvider
        SPI method to get the rules for the zone ID.

        This loads the rules for the region and version specified. The version may be null to indicate the "latest" version.

        Specified by:
        provideRules in class ZoneRulesProvider
        Parameters:
        zoneId - the time-zone region ID, not null
        Returns:
        the rules, not null
      • provideVersions

        protected java.util.NavigableMap<java.lang.String,​ZoneRules> provideVersions​(java.lang.String zoneId)
        Description copied from class: ZoneRulesProvider
        SPI method to get the history of rules for the zone ID.

        This returns a map of historical rules keyed by a version string. The exact meaning and format of the version is provider specific. The version must follow lexicographical order, thus the returned map will be order from the oldest known rules to the newest available rules. The default 'TZDB' group uses version numbering consisting of the year followed by a letter, such as '2009e' or '2012f'.

        Implementations must provide a result for each valid zone ID, however they do not have to provide a history of rules. Thus the map will always contain one element, and will only contain more than one element if historical rule information is available.

        The returned versions remain available and valid for the lifetime of the application. A dynamic provider may increase the set of versions as more data becomes available.

        Specified by:
        provideVersions in class ZoneRulesProvider
        Parameters:
        zoneId - the zone region ID as used by ZoneId, not null
        Returns:
        a modifiable copy of the history of the rules for the ID, sorted from oldest to newest, not null
      • load

        private boolean load​(java.lang.ClassLoader classLoader)
        Loads the rules.
        Parameters:
        classLoader - the class loader to use, not null
        Returns:
        true if updated
        Throws:
        ZoneRulesException - if unable to load
      • load

        private boolean load​(java.net.URL url)
                      throws java.lang.ClassNotFoundException,
                             java.io.IOException,
                             ZoneRulesException
        Loads the rules from a URL, often in a jar file.
        Parameters:
        url - the jar file to load, not null
        Returns:
        true if updated
        Throws:
        java.lang.ClassNotFoundException - if a classpath error occurs
        java.io.IOException - if an IO error occurs
        ZoneRulesException - if the data is already loaded for the version
      • load

        private boolean load​(java.io.InputStream in)
                      throws java.io.IOException,
                             java.io.StreamCorruptedException
        Loads the rules from an input stream.
        Parameters:
        in - the stream to load, not null, not closed after use
        Throws:
        java.lang.Exception - if an error occurs
        java.io.IOException
        java.io.StreamCorruptedException
      • loadData

        private java.lang.Iterable<TzdbZoneRulesProvider.Version> loadData​(java.io.InputStream in)
                                                                    throws java.io.IOException,
                                                                           java.io.StreamCorruptedException
        Loads the rules from an input stream.
        Parameters:
        in - the stream to load, not null, not closed after use
        Throws:
        java.lang.Exception - if an error occurs
        java.io.IOException
        java.io.StreamCorruptedException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object