Package com.oorian.utils
Class OorianFile
java.lang.Object
com.oorian.utils.OorianFile
- Direct Known Subclasses:
ResourceFile,ServerFile
Abstract base class for unified file access across different sources (classpath, filesystem, etc.).
Subclasses provide the getInputStream() implementation for their specific source.
Common read operations are provided as default methods that delegate to getInputStream().
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionabstract booleanexists()Returns whether this file exists and is accessible.abstract InputStreamReturns anInputStreamfor reading this file's contents.getName()Returns the filename extracted from the path, handling both forward and back slashes.abstract StringgetPath()Returns the path of this file as provided at construction time.read()Reads the entire file contents as a UTF-8 string.byte[]Reads the entire file contents as a byte array.Reads all lines from this file as a list of strings using UTF-8 encoding.readAsString(Charset charset) Reads the entire file contents as a string using the specified charset.
-
Constructor Details
-
OorianFile
public OorianFile()
-
-
Method Details
-
getInputStream
Returns anInputStreamfor reading this file's contents.- Returns:
- an input stream for this file.
- Throws:
IOException- if the file cannot be opened or does not exist.
-
exists
public abstract boolean exists()Returns whether this file exists and is accessible.- Returns:
trueif the file exists,falseotherwise.
-
getPath
Returns the path of this file as provided at construction time.- Returns:
- the file path.
-
getName
Returns the filename extracted from the path, handling both forward and back slashes.- Returns:
- the filename portion of the path.
-
read
Reads the entire file contents as a UTF-8 string.- Returns:
- the file contents as a string.
- Throws:
IOException- if an I/O error occurs.
-
readAsLines
Reads all lines from this file as a list of strings using UTF-8 encoding.- Returns:
- a list of lines from the file.
- Throws:
IOException- if an I/O error occurs.
-
readAsString
Reads the entire file contents as a string using the specified charset.- Parameters:
charset- the charset to use for decoding.- Returns:
- the file contents as a string.
- Throws:
IOException- if an I/O error occurs.
-
readAsBytes
Reads the entire file contents as a byte array.- Returns:
- the file contents as a byte array.
- Throws:
IOException- if an I/O error occurs.
-