Record Class JarPath

java.lang.Object
java.lang.Record
com.yetnt.utils.io.JarPath
Record Components:
path - The path in the resources folder to this file.

public record JarPath(String path) extends Record
basically a String except this has a readAs(Class, Function) and read(Class, Consumer) methods such as to allow Class.getResourceAsStream(String) reading via an anonymous function.

From J3Engine

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private final String
    The field for the path record component.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates an instance of a JarPath record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    final int
    Returns a hash code value for this object.
    Returns the value of the path record component.
    void
    read(Class<?> relative, Consumer<InputStream> func)
    Reads the file with the given function
    <T> T
    readAs(Class<?> relative, Function<InputStream,T> func)
    Reads the file with the given function and returns a result
    final String
    Returns a string representation of this record class.

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, notify, notifyAll, wait, wait, wait
  • Field Details

    • path

      private final String path
      The field for the path record component.
  • Constructor Details

    • JarPath

      public JarPath(String path)
      Creates an instance of a JarPath record class.
      Parameters:
      path - the value for the path record component
  • Method Details

    • readAs

      public <T> T readAs(Class<?> relative, Function<InputStream,T> func) throws IOException
      Reads the file with the given function and returns a result
      Type Parameters:
      T - The type of the result returned by the reader func
      Parameters:
      relative - The class whose project resources should be read
      func - The function to read the file and return a result.
      Returns:
      The result returned by the reader func
      Throws:
      IOException - if any Io shit happens
    • read

      public void read(Class<?> relative, Consumer<InputStream> func) throws IOException
      Reads the file with the given function
      Parameters:
      relative - The class whose project resources should be read
      func - The function to read the file.
      Throws:
      IOException - if any Io shit happens
    • toString

      public final 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
      Returns:
      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
      Returns:
      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
      Parameters:
      o - the object with which to compare
      Returns:
      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.
      Returns:
      the value of the path record component