Package org.geysermc.geyser.util
Class FileUtils
java.lang.Object
org.geysermc.geyser.util.FileUtils
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]calculateSHA1(Path path) Calculate the SHA1 hash of a filestatic byte[]calculateSHA256(Path path) Calculate the SHA256 hash of a filestatic FilefileOrCopiedFromResource(File file, String name, Function<String, String> format, GeyserBootstrap bootstrap) Open the specified file or copy if from resourcesgetGeneratedClassesForAnnotation(Class<? extends Annotation> annotationClass) Returns a set of all the classes that are annotated by a given annotation.Returns a set of all the classes that are annotated by a given annotation.static <T> TloadConfig(File src, Class<T> valueType) Load the given YAML file into the given classstatic <T> TloadJson(InputStream src, Class<T> valueType) static byte[]readAllBytes(String resource) readAllLines(Path path) Read the lines of a file and return it as a streamstatic StringreadToString(String resource) static voidWrites the given data to the specified file on diskstatic voidWrites the given data to the specified file on disk
-
Constructor Details
-
FileUtils
public FileUtils()
-
-
Method Details
-
loadConfig
Load the given YAML file into the given class- Type Parameters:
T- the type- Parameters:
src- File to loadvalueType- Class to load file into- Returns:
- The data as the given class
- Throws:
IOException- if the config could not be loaded
-
loadJson
- Throws:
IOException
-
fileOrCopiedFromResource
public static File fileOrCopiedFromResource(File file, String name, Function<String, String> format, GeyserBootstrap bootstrap) throws IOExceptionOpen the specified file or copy if from resources- Parameters:
file- File to openname- Name of the resource get if neededformat- Formatting callback- Returns:
- File handle of the specified file
- Throws:
IOException- if the file failed to copy from resource
-
writeFile
Writes the given data to the specified file on disk- Parameters:
file- File to write todata- Data to write to the file- Throws:
IOException- if the file failed to write
-
writeFile
Writes the given data to the specified file on disk- Parameters:
name- File path to write todata- Data to write to the file- Throws:
IOException- if the file failed to write
-
calculateSHA256
Calculate the SHA256 hash of a file- Parameters:
path- Path to calculate the hash for- Returns:
- A byte[] representation of the hash
-
calculateSHA1
Calculate the SHA1 hash of a file- Parameters:
path- Path to calculate the hash for- Returns:
- A byte[] representation of the hash
-
readAllBytes
- Parameters:
resource- the internal resource to read off from- Returns:
- the byte array of an InputStream
-
readToString
- Parameters:
resource- the internal resource to read off from- Returns:
- the contents decoded as a UTF-8 String
-
readAllLines
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
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
-