public class FileUtils extends Object
| Constructor and Description |
|---|
FileUtils() |
| Modifier and Type | Method and Description |
|---|---|
static byte[] |
calculateSHA1(File file)
Calculate the SHA1 hash of a file
|
static byte[] |
calculateSHA256(File file)
Calculate the SHA256 hash of a file
|
static File |
fileOrCopiedFromResource(File file,
String name,
Function<String,String> format)
Open the specified file or copy if from resources
|
static File |
fileOrCopiedFromResource(String name,
Function<String,String> fallback)
Open the specified file or copy if from resources
|
static org.reflections.Reflections |
getReflections(String path)
Get the stored reflection data for a given path
|
static InputStream |
getResource(String resource)
Get an InputStream for the given resource path, throws AssertionError if resource is not found
|
static <T> T |
loadConfig(File src,
Class<T> valueType)
Load the given YAML file into the given class
|
static <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 of
Files.readAllBytes(java.nio.file.Path) |
static void |
writeFile(File file,
char[] data)
Writes the given data to the specified file on disk
|
static void |
writeFile(String name,
char[] data)
Writes the given data to the specified file on disk
|
public static <T> T loadConfig(File src, Class<T> valueType) throws IOException
T - the typesrc - File to loadvalueType - Class to load file intoIOException - if the config could not be loadedpublic static <T> T loadYaml(InputStream src, Class<T> valueType) throws IOException
IOExceptionpublic static <T> T loadJson(InputStream src, Class<T> valueType) throws IOException
IOExceptionpublic static File fileOrCopiedFromResource(String name, Function<String,String> fallback) throws IOException
name - File and resource namefallback - Formatting callbackIOException - if the file failed to copy from resourcepublic static File fileOrCopiedFromResource(File file, String name, Function<String,String> format) throws IOException
file - File to openname - Name of the resource get if neededformat - Formatting callbackIOException - if the file failed to copy from resourcepublic static void writeFile(File file, char[] data) throws IOException
file - File to write todata - Data to write to the fileIOException - if the file failed to writepublic static void writeFile(String name, char[] data) throws IOException
name - File path to write todata - Data to write to the fileIOException - if the file failed to writepublic static InputStream getResource(String resource)
resource - Resource to getpublic static byte[] calculateSHA256(File file)
file - File to calculate the hash forpublic static byte[] calculateSHA1(File file)
file - File to calculate the hash forpublic static org.reflections.Reflections getReflections(String path)
path - The path to get the reflection data forpublic static byte[] readAllBytes(File file)
Files.readAllBytes(java.nio.file.Path)file - File to read bytes ofCopyright © 2020 GeyserMC. All rights reserved.