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
    • loadJson

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

      public static File fileOrCopiedFromResource(File file, String name, Function<String,String> format, GeyserBootstrap bootstrap) 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
    • calculateSHA256

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

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

      public static byte[] readAllBytes(String resource)
      Parameters:
      resource - the internal resource to read off from
      Returns:
      the byte array of an InputStream
    • readToString

      public static String readToString(String resource)
      Parameters:
      resource - the internal resource to read off from
      Returns:
      the contents decoded as a UTF-8 String
    • 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