Package org.confng.util
Class FileResolver
- java.lang.Object
-
- org.confng.util.FileResolver
-
public class FileResolver extends Object
Utility class for resolving and reading configuration files from both filesystem and classpath (including JAR resources).This class provides a centralized way to handle file loading that works consistently across different deployment scenarios:
- Files on the filesystem
- Files in the classpath (e.g., src/main/resources)
- Files inside JAR files
- Since:
- 1.0.3
- Author:
- Bharat Kumar Malviya, GitHub: github.com/imBharatMalviya
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classFileResolver.ResolvedFileResult of file resolution containing the resolved path and metadata.
-
Constructor Summary
Constructors Constructor Description FileResolver()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static booleanexists(String filePath)Checks if a file exists in either filesystem or classpath.static StringgetFileName(String filePath)Gets the filename (without path) from a file path.static InputStreamopenInputStream(String filePath)Opens an InputStream for reading a file from either filesystem or classpath.static ReaderopenReader(String filePath)Opens a Reader for reading a file from either filesystem or classpath.static FileResolver.ResolvedFileresolve(String filePath)Resolves a file path by checking filesystem first, then classpath.
-
-
-
Method Detail
-
resolve
public static FileResolver.ResolvedFile resolve(String filePath)
Resolves a file path by checking filesystem first, then classpath. For JAR resources, creates a temporary file that will be deleted on JVM exit.- Parameters:
filePath- the file path to resolve- Returns:
- a ResolvedFile containing the resolved path and metadata, or null if not found
-
openInputStream
public static InputStream openInputStream(String filePath) throws IOException
Opens an InputStream for reading a file from either filesystem or classpath.- Parameters:
filePath- the file path to read- Returns:
- an InputStream for reading the file
- Throws:
IOException- if the file cannot be opened or doesn't exist
-
openReader
public static Reader openReader(String filePath) throws IOException
Opens a Reader for reading a file from either filesystem or classpath.- Parameters:
filePath- the file path to read- Returns:
- a Reader for reading the file
- Throws:
IOException- if the file cannot be opened or doesn't exist
-
exists
public static boolean exists(String filePath)
Checks if a file exists in either filesystem or classpath.- Parameters:
filePath- the file path to check- Returns:
- true if the file exists
-
-