Package nl.knaw.dans.bagit.hash
Class Hasher.HashOptions
java.lang.Object
nl.knaw.dans.bagit.hash.Hasher.HashOptions
- Enclosing class:
- Hasher
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 Summary
FieldsModifier and TypeFieldDescriptionprivate final intprivate final booleanprivate final intprivate final intprivate final int -
Constructor Summary
ConstructorsConstructorDescriptionHashOptions(int chunkSize, int maxRetries, int retrySleepMs, int maxRedirects, boolean fallBackToFullStreamOnRangeFail) Constructs an instance ofHashOptionswith specific configuration settings for chunk size, retry behavior, and redirection limits. -
Method Summary
Modifier and TypeMethodDescriptionintintintintbooleanstatic Hasher.HashOptionsCreates an instance ofHashOptionsusing system properties to determine the configuration values for chunk size, maximum retries, retry sleep time, and maximum redirects.withOverrides(Integer chunkSize, Integer maxRetries, Integer retrySleepMs, Integer maxRedirects) Returns a newHashOptionsinstance with the specified overrides for configuration parameters.withOverrides(Integer chunkSize, Integer maxRetries, Integer retrySleepMs, Integer maxRedirects, Boolean fallBackToFullStreamOnRangeFail) Returns a newHashOptionsinstance with the specified overrides for configuration parameters.
-
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 ofHashOptionswith specific configuration settings for chunk size, retry behavior, and redirection limits.- Parameters:
chunkSize- the size of data chunks in bytes; must be greater than 0maxRetries- the maximum number of retry attempts; must be greater than 0retrySleepMs- the time in milliseconds to sleep between retriesmaxRedirects- 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
Creates an instance ofHashOptionsusing 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
HashOptionsinstance 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 newHashOptionsinstance with the specified overrides for configuration parameters. If a parameter isnull, the existing value from the currentHashOptionsinstance is used.- Parameters:
chunkSize- the size of data chunks in bytes; ifnull, the existing chunk size is retainedmaxRetries- the maximum number of retry attempts; ifnull, the existing max retries value is retainedretrySleepMs- the time in milliseconds to sleep between retries; ifnull, the existing retry sleep time is retainedmaxRedirects- the maximum number of redirects allowed; ifnull, the existing max redirects value is retained- Returns:
- a new
HashOptionsinstance with the specified values or the existing values if overrides arenull - 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 newHashOptionsinstance with the specified overrides for configuration parameters. If a parameter isnull, the existing value from the currentHashOptionsinstance is used.- Parameters:
chunkSize- the size of data chunks in bytes; ifnull, the existing chunk size is retainedmaxRetries- the maximum number of retry attempts; ifnull, the existing max retries value is retainedretrySleepMs- the time in milliseconds to sleep between retries; ifnull, the existing retry sleep time is retainedmaxRedirects- the maximum number of redirects allowed; ifnull, the existing max redirects value is retainedfallBackToFullStreamOnRangeFail- whether to fall back to full stream; ifnull, the existing value is retained- Returns:
- a new
HashOptionsinstance with the specified values or the existing values if overrides arenull - 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()
-