Package org.geysermc.geyser.util
Class FileUtils
java.lang.Object
org.geysermc.geyser.util.FileUtils
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic byte[]
calculateSHA1(File file)
Calculate the SHA1 hash of a filestatic byte[]
calculateSHA256(File file)
Calculate the SHA256 hash of a filestatic File
Open the specified file or copy if from resourcesstatic File
fileOrCopiedFromResource(String name, Function<String,String> fallback)
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 InputStream
getResource(String resource)
Get an InputStream for the given resource path, throws AssertionError if resource is not foundstatic <T> T
loadConfig(File src, Class<T> valueType)
Load the given YAML file into the given classstatic <T> T
loadJson(InputStream src, Class<T> valueType)
static <T> T
loadYaml(InputStream src, Class<T> valueType)
static byte[]
readAllBytes(File file)
An android compatible version ofFiles.readAllBytes(java.nio.file.Path)
static byte[]
readAllBytes(InputStream stream)
readAllLines(Path path)
Read the lines of a file and return it as a streamstatic void
Writes the given data to the specified file on diskstatic void
Writes 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
-
loadYaml
- Throws:
IOException
-
loadJson
- Throws:
IOException
-
fileOrCopiedFromResource
public static File fileOrCopiedFromResource(String name, Function<String,String> fallback) throws IOExceptionOpen the specified file or copy if from resources- Parameters:
name
- File and resource namefallback
- 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 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
-
getResource
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
Calculate the SHA256 hash of a file- Parameters:
file
- File to calculate the hash for- Returns:
- A byte[] representation of the hash
-
calculateSHA1
Calculate the SHA1 hash of a file- Parameters:
file
- File to calculate the hash for- Returns:
- A byte[] representation of the hash
-
readAllBytes
An android compatible version ofFiles.readAllBytes(java.nio.file.Path)
- Parameters:
file
- File to read bytes of- Returns:
- The byte array of the file
-
readAllBytes
- Parameters:
stream
- the InputStream to read off of- Returns:
- the byte array of an InputStream
-
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
-