Usage - Zeanon/StorageManager GitHub Wiki

Usage

Initialization

ThunderFile thunder = StorageManager.thunderFile(file).create();

This would be the most rudimentary way of creating a usable File-Object.
thunderFile as follows:

thunderFile(File file)
thunderFile(Path file)
thunderFile(String name)
thunderFile(String directory, String name)
thunderFile(File directory, String name)
thunderFile(Path directory, String name)

jsonFile(), tomlFile() and so on is used in the same manner.
If you only give the name, the file will be created relative to the folder the program is in.

There are also additional arguments, with which you can define the ReloadSetting, the DataType, the ConfigSetting and import Data directly on creation of the file.

reloadSetting(ReloadSettingBase reloadSetting)

commentSetting(CommentSettingBase commentSetting)

dataType(DataTypeBase dataType)

fromInputStream(InputStream inputStream)

fromFile(File file)
fromFile(Path file)
fromFile(String)
fromFile(String directory, String name)
fromFile(File directory, String name)
fromFile(Path directory, String name)

fromResource(String resource)

The resource in fromResource refers to an internal resource in the program.
To use the Builder just concatenate the methods, the only important thing is, that the last method is a as* method. A more ellaborate example would be:

ThunderFile thunder = StorageManager
                            .thunderFile(FILE)
                            .fromResource("resources/thunder.tf")
                            .reloadSetting(Reload.MANUAL)
                            .configSetting(Comment.SKIP)
                            .dataType(DataType.STANDARD)
                            .create();

Default

The default Settings for normal Files are Comment.SKIP, Reload.INTELLIGENT and DataType.AUTOMATIC DataType.AUTOMATIC means the way it's stored depends on the CommentSetting(SKIP uses STANDARD[non sorted] and PRESERVE uses SORTED)
For the Config versions the default is Comment.PRESERVE.

Explanations

DataTypes

DataType.STANDARD uses a bit less RAM for caching the Data, but on the other Hand the Data is not sorted, which means, that when writing back to the File it might mess up the arrangement and the sequence(it wont make the file unreadable, just the Style might be messed up).
This Storage type is best suited for Files that are only read from and not wrote to by the program or when storing Data.

DataType.SORTED on the other hand is internally sorted, which uses a bit mor RAM, but when writing back to the File everything will look the same except for the values that have been changed.
This Storage type is best suited for Files that are also written to by the program but also neat to keep their internal structure.

ReloadSetting


Reload.MANUAL means that the FileData will only be reloaded, when you call the reload() method.
Reload.AUTOMATIC means that it will reload the File everytime you access it.
Reload.INTELLIGENT means that it will only reload when the FileContent has changed since the last access.


General Usage

To get a value you can just use get(key) (or getString for a String, getByte for a Byte and so on...), the key in this case should be in the format key.subkey.
You can also use hasKey(key) to check whether a given key exists.
To set a value use set(key, value). While the value can be of any Type and StorageManager supports all of the basic Object Types as String, Long, and so on you might have to add your own parsing to and from String for certain special and complicated Object Types.
To remove a Key from the File you can use remove(key) or set(key, null).
Another nice feature is that it will only write to the File if the cached data actually changed, so for example if we have this.is.a.example = true and you use set("this.is.a.example", true) nothing will happen.
If you wish to clear the File of all it's content you can do that by using clear().
You can also use the setFileContentFrom* methods to rewrite the content of the File.
To check if the File has changed since the last reload use hasChanged().
To get the keySets use keySet(), keySet(key), singleLayerKeySet() or singleLayerKeySet(key).
You can also replace a certain CharSequence in the whole File by using replace(target, replacement).
You can also change the different Settings on the go by using their Setters.

⚠️ **GitHub.com Fallback** ⚠️