package com.github.qrokodial.sparkle.utilities.io.properties;

import com.github.qrokodial.sparkle.utilities.casting.CastableDatabase;

import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.Optional;

public class PropertiesFile extends ReadablePropertiesFile implements CastableDatabase<String, String> {
    private File file;

    /**
     * Instantiates the class.
     *
     * @param file
     */
    public PropertiesFile(File file) throws IOException {
        super(new FileInputStream(file));
    }

    /**
     * @return the underlying file
     */
    public File getFile() {
        return file;
    }

    /**
     * Sets the underlying file.
     *
     * @param file
     */
    public void setFile(File file) {
        this.file = file;
    }

    /**
     * Reloads the contents of the database.
     */
    public void reload() throws IOException {
        super.reload(new FileInputStream(getFile()));
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void put(String key, String value) {
        map.put(key, value);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Optional<String> remove(String key) {
        return map.remove(key);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public void clear() {
        map.clear();
    }
}

@@ -210,16 +210,86 @@
 eption;%0A
+import java.nio.charset.StandardCharsets;%0Aimport java.nio.file.Files;%0A
 import j
@@ -1029,32 +1029,483 @@
 ile()));%0A    %7D%0A%0A
+    /**%0A     * Saves the contents of the database.%0A     */%0A    public void save() throws IOException %7B%0A        StringBuilder buffer = new StringBuilder();%0A%0A        for (String key : keySet()) %7B%0A            buffer.append(key);%0A            buffer.append(%22=%22);%0A            buffer.append(getString(key).get());%0A            buffer.append(%22%5Cn%22);%0A        %7D%0A%0A        Files.write(getFile().toPath(), buffer.toString().getBytes(StandardCharsets.UTF_8));%0A    %7D%0A%0A
     /**%0A     * %7B

Implement PropertiesFile#save