Class ExternalResourceMillisecondStoreDataProvider

java.lang.Object
org.lukashian.store.external.ExternalResourceMillisecondStoreDataProvider
All Implemented Interfaces:
MillisecondStoreDataProvider
Direct Known Subclasses:
FileMillisecondStoreDataProvider, HttpMillisecondStoreDataProvider

public abstract class ExternalResourceMillisecondStoreDataProvider extends Object implements MillisecondStoreDataProvider
This class provides base functionality for loading numbers of milliseconds from an external resource, like a file or a url. This allows for centralized maintenance and governance of the exact numbers that define an instance of the calendar.

A MillisecondStoreDataProvider needs to provide three things: the unix epoch offset, the milliseconds of the years and the milliseconds of the days. Please see the javadoc of MillisecondStoreDataProvider for more details.

An ExternalResourceMillisecondStoreDataProvider requires a base location and three extensions, one for each method of @MillisecondStoreDataProvider. It then loads the required values by combining the base location with each extension. The base location can, for example, be a directory or a url. The extensions then point to individual files at that base location. The base location should always end with a path separator, because the extensions are added to the base location as is.

Default values are given for the extensions corresponding to the three things that need to be provided by the MillisecondStoreDataProvider. Implementations that use these defaults then only need to specify the base location.

Loading of the milliseconds is done by loading a binary stream from the specified location. This binary stream should encode the long values that represent the milliseconds. Each consecutive 8 bytes of the stream should correspond to an individual millisecond. This binary stream is then decoded into an array of longs. For the unix epoch offset, only a single long value (i.e. 8 bytes) should be returned in the binary stream.

The actual mechanism for loading the binary stream is left to subclasses of this class, so that various implementations can provide functionality for loading the milliseconds from various kinds of external resources, such as files, http urls, etc. See loadMilliseconds(String) for details.

  • Field Details

    • DEFAULT_UNIX_EPOCH_OFFSET_EXTENSION

      public static final String DEFAULT_UNIX_EPOCH_OFFSET_EXTENSION
      See Also:
    • DEFAULT_YEAR_EPOCH_MILLISECONDS_EXTENSION

      public static final String DEFAULT_YEAR_EPOCH_MILLISECONDS_EXTENSION
      See Also:
    • DEFAULT_DAY_EPOCH_MILLISECONDS_EXTENSION

      public static final String DEFAULT_DAY_EPOCH_MILLISECONDS_EXTENSION
      See Also:
  • Constructor Details

    • ExternalResourceMillisecondStoreDataProvider

      public ExternalResourceMillisecondStoreDataProvider(String baseLocation, String unixEpochOffsetExtension, String yearEpochMillisecondsExtension, String dayEpochMillisecondsExtension)
      Creates an ExternalResourceMillisecondStoreDataProvider that loads arrays of milliseconds from the specified base location and extensions. The base location should always end with a path separator, because the extensions are added to the base location as is.
    • ExternalResourceMillisecondStoreDataProvider

      public ExternalResourceMillisecondStoreDataProvider(String baseLocation)
      Creates an ExternalResourceMillisecondStoreDataProvider that loads arrays of milliseconds from the specified base location, using the default extensions. The base location should always end with a path separator, because the extensions are added to the base location as is.
  • Method Details

    • loadUnixEpochOffsetMilliseconds

      public long loadUnixEpochOffsetMilliseconds()
      Specified by:
      loadUnixEpochOffsetMilliseconds in interface MillisecondStoreDataProvider
    • loadYearEpochMilliseconds

      public long[] loadYearEpochMilliseconds()
      Specified by:
      loadYearEpochMilliseconds in interface MillisecondStoreDataProvider
    • loadDayEpochMilliseconds

      public long[] loadDayEpochMilliseconds(long[] yearEpochMilliseconds)
      Specified by:
      loadDayEpochMilliseconds in interface MillisecondStoreDataProvider
    • loadMillisecondsByteArray

      protected abstract byte[] loadMillisecondsByteArray(String location) throws Exception
      Loads an array of bytes from the specified location. This location is a concatenation of the base location and one of the extensions, depending on which of the values needs loading.

      This method needs to return a binary stream from the specified location. This binary stream should encode the long values that represent the milliseconds. Each consecutive 8 bytes of the stream should correspond to an individual millisecond. This binary stream is then decoded into an array of longs. For the unix epoch offset, only a single long value (i.e. 8 bytes) should be returned in the binary stream.

      Throws:
      Exception