Package me.croabeast.file
Class ResourceUtils
java.lang.Object
me.croabeast.file.ResourceUtils
The
ResourceUtils class provides utility methods for handling file resources,
such as saving resources to the file system and constructing file paths.
It contains methods to save an InputStream resource to a specified location within
a data folder and to resolve file paths relative to a parent directory.
- See Also:
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionCreates aFileobject by resolving the specified child file paths against the given parent directory.voidsaveResource(@Nullable InputStream resource, File dataFolder, String path) Saves the specified resource to the given file path within the data folder.voidsaveResource(@Nullable InputStream resource, File dataFolder, String path, boolean replace) Saves the specified resource to the given file path within the data folder.
-
Constructor Details
-
ResourceUtils
public ResourceUtils()
-
-
Method Details
-
saveResource
public void saveResource(@Nullable @Nullable InputStream resource, File dataFolder, String path, boolean replace) Saves the specified resource to the given file path within the data folder.If the target directory does not exist, it will be created. If a file already exists at the target location and
replaceisfalse, anUnsupportedOperationExceptionis thrown.- Parameters:
resource- the input stream of the resource to save; must not benull.dataFolder- the data folder where the resource will be saved; must not benull.path- the file path within the data folder to save the resource to; must not benull.replace- whether to replace the existing file if it already exists.- Throws:
NullPointerException- if thepathorresourceisnull.UnsupportedOperationException- if the file already exists andreplaceisfalse, or if an IO error occurs during saving.
-
saveResource
Saves the specified resource to the given file path within the data folder.This method behaves like
saveResource(InputStream, File, String, boolean)withreplaceset tofalse. Existing files will not be replaced.- Parameters:
resource- the input stream of the resource to save; must not benull.dataFolder- the data folder where the resource will be saved; must not benull.path- the file path within the data folder to save the resource to; must not benull.- Throws:
NullPointerException- if thepathorresourceisnull.UnsupportedOperationException- if the file already exists or if an IO error occurs during saving.
-
fileFrom
Creates aFileobject by resolving the specified child file paths against the given parent directory.The method iteratively appends each element in
childPathsto theparentdirectory, producing a finalFilethat represents the nested file location.- Parameters:
parent- the parent directory to resolve the child file paths against; must not benull.childPaths- the relative paths of the child files.- Returns:
- the
Fileobject representing the specified child file paths within the parent directory. - Throws:
NullPointerException- if theparentdirectory isnull.
-