Class Hasher.HashOptions

java.lang.Object
nl.knaw.dans.bagit.hash.Hasher.HashOptions
Enclosing class:
Hasher

public static final class Hasher.HashOptions extends Object
Represents configuration options for hashing operations. This class is immutable and provides various configurable parameters such as chunk size, retry behavior, and redirection limits.
  • Field Details

    • chunkSize

      private final int chunkSize
    • maxRetries

      private final int maxRetries
    • retrySleepMs

      private final int retrySleepMs
    • maxRedirects

      private final int maxRedirects
    • fallBackToFullStreamOnRangeFail

      private final boolean fallBackToFullStreamOnRangeFail
  • Constructor Details

    • HashOptions

      public HashOptions(int chunkSize, int maxRetries, int retrySleepMs, int maxRedirects, boolean fallBackToFullStreamOnRangeFail)
      Constructs an instance of HashOptions with specific configuration settings for chunk size, retry behavior, and redirection limits.
      Parameters:
      chunkSize - the size of data chunks in bytes; must be greater than 0
      maxRetries - the maximum number of retry attempts; must be greater than 0
      retrySleepMs - the time in milliseconds to sleep between retries
      maxRedirects - the maximum number of redirects allowed; must be greater than or equal to 0
      Throws:
      IllegalArgumentException - if any of the provided values are invalid (e.g., negative or zero where not allowed)
  • Method Details

    • systemProperties

      public static Hasher.HashOptions systemProperties()
      Creates an instance of HashOptions using system properties to determine the configuration values for chunk size, maximum retries, retry sleep time, and maximum redirects. Defaults are used if the respective system properties are not set. The following system properties are used: - CHUNK_SIZE_PROP: Configures the chunk size in bytes (default: DEFAULT_CHUNK_SIZE). - MAX_RETRIES_PROP: Configures the maximum number of retry attempts (default: DEFAULT_MAX_RETRIES). - RETRY_SLEEP_MS_PROP: Configures the sleep time in milliseconds between retries (default: DEFAULT_RETRY_SLEEP_MS). - MAX_REDIRECTS_PROP: Configures the maximum allowable redirects (default: DEFAULT_MAX_REDIRECTS).
      Returns:
      a HashOptions instance populated with configuration values derived from system properties or their default values.
      Throws:
      IllegalArgumentException - if any of the retrieved values are invalid (e.g., negative or zero where not allowed)
    • withOverrides

      public Hasher.HashOptions withOverrides(Integer chunkSize, Integer maxRetries, Integer retrySleepMs, Integer maxRedirects)
      Returns a new HashOptions instance with the specified overrides for configuration parameters. If a parameter is null, the existing value from the current HashOptions instance is used.
      Parameters:
      chunkSize - the size of data chunks in bytes; if null, the existing chunk size is retained
      maxRetries - the maximum number of retry attempts; if null, the existing max retries value is retained
      retrySleepMs - the time in milliseconds to sleep between retries; if null, the existing retry sleep time is retained
      maxRedirects - the maximum number of redirects allowed; if null, the existing max redirects value is retained
      Returns:
      a new HashOptions instance with the specified values or the existing values if overrides are null
      Throws:
      IllegalArgumentException - if any of the provided values are invalid (e.g., negative or zero where not allowed)
    • withOverrides

      public Hasher.HashOptions withOverrides(Integer chunkSize, Integer maxRetries, Integer retrySleepMs, Integer maxRedirects, Boolean fallBackToFullStreamOnRangeFail)
      Returns a new HashOptions instance with the specified overrides for configuration parameters. If a parameter is null, the existing value from the current HashOptions instance is used.
      Parameters:
      chunkSize - the size of data chunks in bytes; if null, the existing chunk size is retained
      maxRetries - the maximum number of retry attempts; if null, the existing max retries value is retained
      retrySleepMs - the time in milliseconds to sleep between retries; if null, the existing retry sleep time is retained
      maxRedirects - the maximum number of redirects allowed; if null, the existing max redirects value is retained
      fallBackToFullStreamOnRangeFail - whether to fall back to full stream; if null, the existing value is retained
      Returns:
      a new HashOptions instance with the specified values or the existing values if overrides are null
      Throws:
      IllegalArgumentException - if any of the provided values are invalid (e.g., negative or zero where not allowed)
    • getChunkSize

      public int getChunkSize()
    • getMaxRetries

      public int getMaxRetries()
    • getRetrySleepMs

      public int getRetrySleepMs()
    • getMaxRedirects

      public int getMaxRedirects()
    • isFallBackToFullStreamOnRangeFail

      public boolean isFallBackToFullStreamOnRangeFail()