<commit_before>package me.gserv.lotterybox.storage;

import com.google.gson.Gson;
import me.gserv.lotterybox.LotteryBox;

import java.io.*;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;

public class DataHandler {

    // Internal storage for the boxes themselves
    HashMap<String, Map<String, Object>> boxes;

    // GSON serializer
    Gson gson = new Gson();

    // Main plugin
    LotteryBox plugin;

    public DataHandler(LotteryBox plugin) {
        this.plugin = plugin;
    }

    @SuppressWarnings("unchecked")
    public boolean load() {
        File fh = new File(this.plugin.getDataFolder() + "/boxes.json");
        if (!fh.exists()) {
            try {
                boolean created = fh.createNewFile();

                if (!created) {
                    this.plugin.getLogger().warning("Unable to create boxes.json!");
                    return false;
                }
            } catch (IOException e) {
                this.plugin.getLogger().warning("Unable to create boxes.json!");
                e.printStackTrace();
                return false;
            }

            this.boxes = new HashMap<>();
            HashMap<String, Object> inner = new HashMap<>();
            inner.put("key", "value");
            inner.put("another key", 2);

            this.boxes.put("box1", inner);

            try (OutputStreamWriter writer = new OutputStreamWriter(new FileOutputStream(fh, false), Charset.forName("UTF-8"))) {
                gson.toJson(this.boxes, writer);
                writer.flush();
                writer.close();
                return true;
            } catch (IOException e) {
                this.plugin.getLogger().warning("Unable to write to boxes.json!");
                e.printStackTrace();
                return false;
            }
        } else {
            try (InputStreamReader reader = new InputStreamReader(new FileInputStream(fh), Charset.forName("UTF-8"))) {
                this.boxes = gson.fromJson(reader, HashMap.class);
                reader.close();
                return true;
            } catch (IOException e) {
                e.printStackTrace();
                return false;
            }
        }
    }
}<commit_msg>More work on the DataHandler<commit_after>package me.gserv.lotterybox.storage;

import com.google.gson.Gson;
import me.gserv.lotterybox.LotteryBox;

import java.io.*;
import java.nio.charset.Charset;
import java.util.HashMap;
import java.util.Map;

public class DataHandler {

    // Internal storage for the boxes themselves
    private HashMap<String, Map<String, Object>> boxes;

    // GSON serializer
    private Gson gson = new Gson();

    // Main plugin
    private LotteryBox plugin;

    // File object
    private File fh;

    public DataHandler(LotteryBox plugin) {
        this.plugin = plugin;
        this.fh = new File(this.plugin.getDataFolder() + "/boxes.json");
    }

    @SuppressWarnings("unchecked")
    public boolean load() {
        if (!this.fh.exists()) {
            this.boxes = new HashMap<>();
            return this.save();
        } else {
            try (
                    InputStreamReader reader = new InputStreamReader(
                            new FileInputStream(this.fh),
                            Charset.forName("UTF-8")
                    )
            ) {
                this.boxes = gson.fromJson(reader, HashMap.class);
                reader.close();
                return true;
            } catch (IOException e) {
                this.plugin.getLogger().warning("Unable to read from boxes data file!");
                e.printStackTrace();
                return false;
            }
        }
    }

    public boolean save() {
        if (!this.fh.exists()) {
            this.plugin.getLogger().info("Boxes data file not found - creating..");
            try {
                boolean created = this.fh.createNewFile();

                if (!created) {
                    this.plugin.getLogger().warning("Unable to create boxes data file!");
                    return false;
                }
            } catch (IOException e) {
                this.plugin.getLogger().warning("Unable to create boxes data file!");
                e.printStackTrace();
                return false;
            }
        }

        try (
                OutputStreamWriter writer = new OutputStreamWriter(
                        new FileOutputStream(this.fh, false),
                        Charset.forName("UTF-8")
                )
        ) {
            gson.toJson(this.boxes, writer);
            writer.flush();
            writer.close();
            return true;
        } catch (IOException e) {
            this.plugin.getLogger().warning("Unable to write boxes data file!");
            e.printStackTrace();
            return false;
        }
    }

    public HashMap<String, Map<String, Object>> getBoxes() {
        return this.boxes;
    }
}
{'fraction_non_alphanumeric': 0.11189516129032258, 'fraction_numerical': 0.0012096774193548388, 'mean_word_length': 1.5987427972760608, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '135092', 'n_tokens_mistral': 1302, 'n_tokens_neox': 1239, 'n_words': 303}