Record Class InputFile

java.lang.Object
java.lang.Record
org.teleight.teleightbots.api.objects.InputFile
All Implemented Interfaces:
Serializable, ApiResult

public record InputFile(String id, File file, String fileName) extends Record implements ApiResult
Represents a file that can be used as an input for API requests. The file can be provided from various sources such as a local file system, a resource from the classpath, a file identified by a Telegram ID stored on the Telegram servers, or a URL.
See Also:
  • Constructor Summary

    Constructors
    Constructor
    Description
    InputFile(String id, File file, String fileName)
    Creates an instance of a InputFile record class.
  • Method Summary

    Modifier and Type
    Method
    Description
    final boolean
    Indicates whether some other object is "equal to" this one.
    Returns the value of the file record component.
    Returns the value of the fileName record component.
    static @NotNull InputFile
    fromFile(@NotNull File file)
    Creates an InputFile instance from a File object.
    static @NotNull InputFile
    fromFile(@NotNull String filePath)
    Creates an InputFile instance from a file path as String.
    static @NotNull InputFile
    fromFile(@NotNull Path filePath)
    Creates an InputFile instance from a file path as Path.
    static @NotNull InputFile
    fromId(@NotNull String id)
    Creates an InputFile instance from a Telegram file ID or URL.
    static @NotNull InputFile
    fromResource(@NotNull String resource)
    Creates an InputFile instance from a resource on the classpath.
    final int
    Returns a hash code value for this object.
    id()
    Returns the value of the id record component.
    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
  • Constructor Details

    • InputFile

      public InputFile(String id, File file, String fileName)
      Creates an instance of a InputFile record class.
      Parameters:
      id - the value for the id record component
      file - the value for the file record component
      fileName - the value for the fileName record component
  • Method Details

    • fromFile

      @NotNull public static @NotNull InputFile fromFile(@NotNull @NotNull File file)
      Creates an InputFile instance from a File object.
      Parameters:
      file - the file to be used as input
      Returns:
      a new InputFile instance containing the provided file
      Throws:
      NullPointerException - if the provided file is null
    • fromFile

      @NotNull public static @NotNull InputFile fromFile(@NotNull @NotNull String filePath)
      Creates an InputFile instance from a file path as String.
      Parameters:
      filePath - the path to the file
      Returns:
      a new InputFile instance containing the file located at the specified path
      Throws:
      NullPointerException - if the provided filePath is null
    • fromFile

      @NotNull public static @NotNull InputFile fromFile(@NotNull @NotNull Path filePath)
      Creates an InputFile instance from a file path as Path.
      Parameters:
      filePath - the path to the file
      Returns:
      a new InputFile instance containing the file located at the specified path
      Throws:
      NullPointerException - if the provided filePath is null
    • fromResource

      @NotNull public static @NotNull InputFile fromResource(@NotNull @NotNull String resource)
      Creates an InputFile instance from a resource on the classpath.

      The resource will be copied to a temporary file, which will be used as the input.

      Parameters:
      resource - the path to the resource within the classpath
      Returns:
      a new InputFile instance containing the resource as a file
      Throws:
      IllegalStateException - if an I/O error occurs while accessing the resource
      NullPointerException - if the provided resource is null
    • fromId

      @NotNull public static @NotNull InputFile fromId(@NotNull @NotNull String id)
      Creates an InputFile instance from a Telegram file ID or URL.
      Parameters:
      id - the Telegram file ID, or URL
      Returns:
      a new InputFile instance containing the Telegram file ID
      Throws:
      NullPointerException - if the provided id is null
    • 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.
    • id

      public String id()
      Returns the value of the id record component.
      Returns:
      the value of the id record component
    • file

      public File file()
      Returns the value of the file record component.
      Returns:
      the value of the file record component
    • fileName

      public String fileName()
      Returns the value of the fileName record component.
      Returns:
      the value of the fileName record component