Class FileUtils

java.lang.Object
org.geysermc.geyser.util.FileUtils

public class FileUtils extends Object
  • Constructor Details

    • FileUtils

      public FileUtils()
  • Method Details

    • loadConfig

      public static <T> T loadConfig(File src, Class<T> valueType) throws IOException
      Load the given YAML file into the given class
      Type Parameters:
      T - the type
      Parameters:
      src - File to load
      valueType - Class to load file into
      Returns:
      The data as the given class
      Throws:
      IOException - if the config could not be loaded
    • loadYaml

      public static <T> T loadYaml(InputStream src, Class<T> valueType) throws IOException
      Throws:
      IOException
    • loadJson

      public static <T> T loadJson(InputStream src, Class<T> valueType) throws IOException
      Throws:
      IOException
    • fileOrCopiedFromResource

      public static File fileOrCopiedFromResource(String name, Function<String,​String> fallback) throws IOException
      Open the specified file or copy if from resources
      Parameters:
      name - File and resource name
      fallback - Formatting callback
      Returns:
      File handle of the specified file
      Throws:
      IOException - if the file failed to copy from resource
    • fileOrCopiedFromResource

      public static File fileOrCopiedFromResource(File file, String name, Function<String,​String> format) throws IOException
      Open the specified file or copy if from resources
      Parameters:
      file - File to open
      name - Name of the resource get if needed
      format - Formatting callback
      Returns:
      File handle of the specified file
      Throws:
      IOException - if the file failed to copy from resource
    • writeFile

      public static void writeFile(File file, char[] data) throws IOException
      Writes the given data to the specified file on disk
      Parameters:
      file - File to write to
      data - Data to write to the file
      Throws:
      IOException - if the file failed to write
    • writeFile

      public static void writeFile(String name, char[] data) throws IOException
      Writes the given data to the specified file on disk
      Parameters:
      name - File path to write to
      data - Data to write to the file
      Throws:
      IOException - if the file failed to write
    • getResource

      public static InputStream getResource(String resource)
      Get an InputStream for the given resource path, throws AssertionError if resource is not found
      Parameters:
      resource - Resource to get
      Returns:
      InputStream of the given resource
    • calculateSHA256

      public static byte[] calculateSHA256(File file)
      Calculate the SHA256 hash of a file
      Parameters:
      file - File to calculate the hash for
      Returns:
      A byte[] representation of the hash
    • calculateSHA1

      public static byte[] calculateSHA1(File file)
      Calculate the SHA1 hash of a file
      Parameters:
      file - File to calculate the hash for
      Returns:
      A byte[] representation of the hash
    • readAllBytes

      public static byte[] readAllBytes(File file)
      An android compatible version of Files.readAllBytes(java.nio.file.Path)
      Parameters:
      file - File to read bytes of
      Returns:
      The byte array of the file
    • readAllBytes

      public static byte[] readAllBytes(InputStream stream)
      Parameters:
      stream - the InputStream to read off of
      Returns:
      the byte array of an InputStream
    • readAllLines

      public static Stream<String> readAllLines(Path path)
      Read the lines of a file and return it as a stream
      Parameters:
      path - File path to read
      Returns:
      The lines as a stream
    • getGeneratedClassesForAnnotation

      public static Set<Class<?>> getGeneratedClassesForAnnotation(Class<? extends Annotation> annotationClass)
      Returns a set of all the classes that are annotated by a given annotation. Keep in mind that these are from a set of generated annotations generated at compile time by the annotation processor, meaning that arbitrary annotations cannot be passed into this method and expected to have a set of classes returned back.
      Parameters:
      annotationClass - the annotation class
      Returns:
      a set of all the classes annotated by the given annotation
    • getGeneratedClassesForAnnotation

      public static Set<Class<?>> getGeneratedClassesForAnnotation(String input)
      Returns a set of all the classes that are annotated by a given annotation. Keep in mind that these are from a set of generated annotations generated at compile time by the annotation processor, meaning that arbitrary annotations cannot be passed into this method and expected to have a set of classes returned back.
      Parameters:
      input - the fully qualified name of the annotation
      Returns:
      a set of all the classes annotated by the given annotation