Record Class ResourceFile

All Implemented Interfaces:

public record ResourceFile(String path) extends Record implements Resource
Reference to a resource file (files included with the application). Resource files can be located both in the classpath and in the local file system. This class can be used to pass around handles to resource files without first having to open those files.

Resource file paths will always use forward slashes as delimiters, regardless of the platform's file separator.

  • Constructor Details

    • ResourceFile

      public ResourceFile(String path)
      Creates an instance of a ResourceFile record class.
      path - the value for the path record component
    • ResourceFile

      public ResourceFile(File file)
  • Method Details

    • getName

      public String getName()
      Returns the name of this resource file. The name is the part of the path after the last path separator. For example, the path "/a/b/c.txt" will return a name of "c.txt".
    • openStream

      public InputStream openStream()
      Specified by:
      openStream in interface Resource
    • openReader

      public BufferedReader openReader(Charset charset)
      Specified by:
      openReader in interface Resource
    • exists

      public boolean exists()
      Returns true if the resource file exists in one of the searched locations.
    • toString

      public String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. All components in this record class are compared with Objects::equals(Object,Object).
      Specified by:
      equals in class Record
      o - the object with which to compare
      true if this object is the same as the o argument; false otherwise.
    • path

      public String path()
      Returns the value of the path record component.
      the value of the path record component