Package io.cui.tools.io
Class FileLoaderUtility
- java.lang.Object
-
- io.cui.tools.io.FileLoaderUtility
-
public final class FileLoaderUtility extends Object
Utility class for dealing with generic / classpath related file access.- Author:
- Oliver Wolff
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static PathcopyFileToTemp(FileLoader source, boolean markDeleteOnExit)Helper class that copies the content of aFileLoaderto the temp-folder and references itstatic FileLoadergetLoaderForPath(String pathName)Returns an implementation ofFileLoadermatching to the given path.static StringtoString(FileLoader fileLoader)Convenience method for reading the content from a givenFileLoaderinto a String read as UTF-8 Stringstatic StringtoString(FileLoader fileLoader, Charset charset)Convenience method for reading the content from a givenFileLoaderinto a Stringstatic StringtoStringUnchecked(FileLoader fileLoader)Convenience method for reading the content from a givenFileLoaderinto a String read as UTF-8 String
-
-
-
Method Detail
-
getLoaderForPath
public static FileLoader getLoaderForPath(String pathName)
Returns an implementation ofFileLoadermatching to the given path.- Parameters:
pathName- must not be null or empty.- Returns:
- a configured implementation of
FileLoader. In case the pathName is prefixed withFileTypePrefix.CLASSPATHit returns aClassPathLoader. If prefixed withFileTypePrefix.URLit returns aUrlLoader. Otherwise, it returns aFileSystemLoader.
-
copyFileToTemp
public static Path copyFileToTemp(FileLoader source, boolean markDeleteOnExit) throws IOException
Helper class that copies the content of aFileLoaderto the temp-folder and references itCaution: Security-Impact
Creating a temp-file might introduce a security issue. Never ever use this location for sensitive information that might be of interest for an attacker- Parameters:
source- must not be null and represent an accessible file, sayingFileLoader.isReadable()markDeleteOnExit- iftruethe file will be marked to delete on Exit.- Returns:
- a reference on a file copied in the temp folder
- Throws:
IOException
-
toString
public static String toString(FileLoader fileLoader, Charset charset) throws IOException
Convenience method for reading the content from a givenFileLoaderinto a String- Parameters:
fileLoader- must not be nullcharset- must not be null- Returns:
- The String content of the File represented by the given
FileLoader - Throws:
IOException
-
toString
public static String toString(FileLoader fileLoader) throws IOException
Convenience method for reading the content from a givenFileLoaderinto a String read as UTF-8 String- Parameters:
fileLoader- must not be null- Returns:
- The String content of the File represented by the given
FileLoader - Throws:
IOException
-
toStringUnchecked
public static String toStringUnchecked(FileLoader fileLoader)
Convenience method for reading the content from a givenFileLoaderinto a String read as UTF-8 String- Parameters:
fileLoader- must not be null- Returns:
- The String content of the File represented by the given
FileLoader - Throws:
IllegalArgumentException- masking the actualIOExceptionNullPointerException- iffileLoaderis null
-
-