Class OorianFile

java.lang.Object
com.oorian.utils.OorianFile
Direct Known Subclasses:
ResourceFile, ServerFile

public abstract class OorianFile extends Object
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 Details

    • OorianFile

      public OorianFile()
  • Method Details

    • getInputStream

      public abstract InputStream getInputStream() throws IOException
      Returns an InputStream for 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:
      true if the file exists, false otherwise.
    • getPath

      public abstract String getPath()
      Returns the path of this file as provided at construction time.
      Returns:
      the file path.
    • getName

      public String getName()
      Returns the filename extracted from the path, handling both forward and back slashes.
      Returns:
      the filename portion of the path.
    • read

      public String read() throws IOException
      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

      public List<String> readAsLines() throws IOException
      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

      public String readAsString(Charset charset) throws IOException
      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

      public byte[] readAsBytes() throws IOException
      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.