Class FileHelper
-
Method Summary
Modifier and TypeMethodDescriptionstatic File
createHiddenFileIfNotExists
(String dataFolder, String internalFolder, String fileName) Creates a hidden file if it does not already existstatic BufferedReader
getBufferedReader
(File file) Gets a buffered reader for reading the given filestatic BufferedReader
getBufferedReader
(File file, String encoding) Gets a buffered reader for reading the given filestatic BufferedReader
getBufferedReaderFromInputStream
(InputStream inputStream) Gets a buffered reader given an input streamstatic BufferedWriter
getBufferedWriter
(File file, boolean appendToFile) Gets a buffered writer for writing to the given filestatic InputStream
Gets an input stream from a string pointing to an internal filelistFilesOfInternalDirectory
(String directory) static void
readInternalFileToMap
(String file, Map<String, String> targetMap) Reads key, value pairs in an internal file to the given mapreadKeyValuePairs
(BufferedReader bufferedReader) Reads key/value pairs from an input streamstatic String
readStreamToString
(InputStream stream) Converts the stream directly into a string, includes the newline characterstatic String
removeUTF8BOM
(String string) Removes the UTF-8 Byte Order Mark if present
-
Method Details
-
getBufferedReader
Gets a buffered reader for reading the given file- Parameters:
file
-The file to read
- Returns:
A buffered reader for reading the given file
- Throws:
FileNotFoundException
-If the given file does not exist
IOException
-
getBufferedReader
Gets a buffered reader for reading the given file- Parameters:
file
-The file to read
encoding
-The encoding of the file
- Returns:
A buffered reader for reading the given file
- Throws:
IOException
-If unable to initialize the buffered reader
-
getBufferedWriter
public static BufferedWriter getBufferedWriter(File file, boolean appendToFile) throws FileNotFoundException Gets a buffered writer for writing to the given file- Parameters:
file
-The file to write to
appendToFile
-Whether the writer should append to the file
- Returns:
A buffered writer for writing to the given file
- Throws:
FileNotFoundException
-If the given file does not exist
-
getInputStreamForInternalFile
Gets an input stream from a string pointing to an internal fileThis is used for getting an input stream for reading a file contained within the compiled .jar file. The file should be in the resources directory, and the file path should start with a forward slash ("/") character.
- Parameters:
file
-The file to read
- Returns:
An input stream for the file
-
getBufferedReaderFromInputStream
Gets a buffered reader given an input stream- Parameters:
inputStream
-The input stream to read
- Returns:
A buffered reader reading the input stream
-
readInternalFileToMap
Reads key, value pairs in an internal file to the given map- Parameters:
file
-The path of the internal file to read
targetMap
-The map to store all found values to
-
readStreamToString
Converts the stream directly into a string, includes the newline character- Parameters:
stream
-The stream to read from
- Returns:
A String of the file read
- Throws:
IOException
-If unable to read the stream
-
listFilesOfInternalDirectory
public static List<Path> listFilesOfInternalDirectory(String directory) throws IOException, URISyntaxException - Throws:
IOException
URISyntaxException
-
readKeyValuePairs
public static Map<String,String> readKeyValuePairs(BufferedReader bufferedReader) throws IOException Reads key/value pairs from an input stream- Parameters:
bufferedReader
-The buffered reader to read
- Returns:
A map containing the read pairs
- Throws:
IOException
-If unable to read from the stream
-
removeUTF8BOM
Removes the UTF-8 Byte Order Mark if present- Parameters:
string
-The string to remove the BOM from
- Returns:
A string guaranteed without a BOM
-
createHiddenFileIfNotExists
public static File createHiddenFileIfNotExists(String dataFolder, String internalFolder, String fileName) throws IOException Creates a hidden file if it does not already exist- Parameters:
dataFolder
-The stargate datafolder
internalFolder
-The hidden datafolder
fileName
-The name of the file to be created
- Returns:
The location of the file created
- Throws:
IOException
-If unable to create the file
-