public class FileManager extends IzouModule implements Runnable
AddOn
or a ReloadableFile
with the path to the directory it is supposed to watchModifier and Type | Class and Description |
---|---|
class |
FileManager.IncompleteFileEventException
Exception thrown if there are multiple Events fired at the same time.
|
log, main
Constructor and Description |
---|
FileManager(Main main)
Creates a new FileManager with a watcher and addOnMap
|
Modifier and Type | Method and Description |
---|---|
void |
createDefaultFile(String defaultFilePath,
String initMessage)
Creates a default File in case it does not exist yet.
|
void |
registerFileDir(Path dir,
String fileType,
ReloadableFile reloadableFile)
Use this method to register a file with the watcherService
|
void |
run()
Main method of fileManager, it constantly waits for new events and then processes them
|
boolean |
writeToFile(String defaultFilePath,
String realFilePath)
Writes default file to real file
The default file would be a file that can be packaged along with the code, from which a real file (say a
properties file for example) can be loaded.
|
debug, debug, error, error, fatal, fatal, getID, getMain
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
isOwner
public FileManager(Main main) throws IOException
main
- an instance of mainIOException
- exception is thrown by watcher servicepublic void registerFileDir(Path dir, String fileType, ReloadableFile reloadableFile) throws IOException
dir
- directory of filefileType
- the name/extension of the file
IMPORTANT: Please try to always enter the full name with extension of the file (Ex: "test.txt"),
it would be best if the fileType is the full file name, and that the file name is clearly
distinguishable from other files.
For example, the property files are stored with the ID of the addon they belong too. That way
every property file is easily distinguishable.reloadableFile
- object of interface that file belongs toIOException
- exception thrown by watcher servicepublic boolean writeToFile(String defaultFilePath, String realFilePath)
defaultFilePath
- path to default file (or where it should be created)realFilePath
- path to real file (that should be filled with content of default file)public void createDefaultFile(String defaultFilePath, String initMessage) throws IOException
defaultFilePath
- path to default file.txt (or where it should be created)initMessage
- the string to write in default fileIOException
- is thrown by bufferedWriterCopyright © 2016. All rights reserved.