Package me.a8kj.config.file
Class PathProviders
java.lang.Object
me.a8kj.config.file.PathProviders
A utility class providing common factory methods for creating
PathProvider instances.
This class offers various strategies for determining the base directory where configurations should be stored.- Since:
- 0.1
- Author:
- a8kj7sea
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic PathProviderCreates a provider that uses the current working directory of the application.static PathProviderCreates a provider that uses a custom string-based absolute path.static PathProviderhybrid(PathProvider primary, PathProvider secondary) Creates a hybrid provider that attempts to use a primary directory if it exists and is writable, otherwise falls back to a secondary directory.static PathProviderCreates a provider that points to the directory where the JAR file of the specified class is located.static PathProviderjarWithUserFallback(Class<?> mainClass) Creates a hybrid provider that prioritizes the JAR's directory and falls back to the user's home directory if the JAR directory is not accessible/writable.static PathProvidertempDir()Creates a provider that points to the system's default temporary directory.static PathProvideruserDir()Creates a provider that points to the current user's home directory.
-
Constructor Details
-
PathProviders
public PathProviders()
-
-
Method Details
-
currentDir
Creates a provider that uses the current working directory of the application.- Returns:
- a
PathProviderpointing to the current absolute path. - Since:
- 0.1
-
userDir
Creates a provider that points to the current user's home directory.- Returns:
- a
PathProviderpointing to the 'user.home' system property path. - Since:
- 0.1
-
jarDir
Creates a provider that points to the directory where the JAR file of the specified class is located. If the location cannot be determined, it fallbacks to the current working directory.- Parameters:
mainClass- the class used to locate the JAR's source code source.- Returns:
- a
PathProviderpointing to the JAR's parent directory. - Since:
- 0.1
-
custom
Creates a provider that uses a custom string-based absolute path.- Parameters:
path- the string representing the custom directory path.- Returns:
- a
PathProviderpointing to the specified path. - Since:
- 0.1
-
tempDir
Creates a provider that points to the system's default temporary directory.- Returns:
- a
PathProviderpointing to the 'java.io.tmpdir' path. - Since:
- 0.1
-
hybrid
Creates a hybrid provider that attempts to use a primary directory if it exists and is writable, otherwise falls back to a secondary directory.- Parameters:
primary- the first choicePathProvider.secondary- the fallbackPathProvider.- Returns:
- a
PathProviderthat evaluates the best available directory. - Since:
- 0.1
-
jarWithUserFallback
Creates a hybrid provider that prioritizes the JAR's directory and falls back to the user's home directory if the JAR directory is not accessible/writable.- Parameters:
mainClass- the class used to locate the JAR.- Returns:
- a
PathProviderwith a jar-to-user fallback strategy. - Since:
- 0.1
-