Search in sources :

Example 1 with ISoliniaLootDropEntryTypeAdapterFactory

use of com.solinia.solinia.Factories.ISoliniaLootDropEntryTypeAdapterFactory in project solinia3-core by mixxit.

the class JsonLootDropRepository method reload.

@Override
public void reload() {
    List<ISoliniaLootDrop> file = new ArrayList<ISoliniaLootDrop>();
    try {
        GsonBuilder gsonbuilder = new GsonBuilder();
        gsonbuilder.registerTypeAdapterFactory(new ISoliniaLootDropEntryTypeAdapterFactory(SoliniaLootDropEntry.class));
        Gson gson = gsonbuilder.create();
        BufferedReader br = new BufferedReader(new FileReader(filePath));
        file = gson.fromJson(br, new TypeToken<List<SoliniaLootDrop>>() {
        }.getType());
    } catch (FileNotFoundException e) {
        e.printStackTrace();
    }
    lootdrops.clear();
    for (ISoliniaLootDrop i : file) {
        lootdrops.put(i.getId(), i);
    }
    System.out.println("Reloaded " + lootdrops.size() + " lootdrops");
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) ISoliniaLootDropEntryTypeAdapterFactory(com.solinia.solinia.Factories.ISoliniaLootDropEntryTypeAdapterFactory) SoliniaLootDropEntry(com.solinia.solinia.Models.SoliniaLootDropEntry) ArrayList(java.util.ArrayList) BufferedReader(java.io.BufferedReader) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) FileReader(java.io.FileReader) ArrayList(java.util.ArrayList) List(java.util.List) ISoliniaLootDrop(com.solinia.solinia.Interfaces.ISoliniaLootDrop)

Example 2 with ISoliniaLootDropEntryTypeAdapterFactory

use of com.solinia.solinia.Factories.ISoliniaLootDropEntryTypeAdapterFactory in project solinia3-core by mixxit.

the class JsonLootDropRepository method commit.

@Override
public void commit() {
    // TODO Auto-generated method stub
    GsonBuilder gsonbuilder = new GsonBuilder();
    // gsonbuilder.setPrettyPrinting();
    gsonbuilder.registerTypeAdapterFactory(new ISoliniaLootDropEntryTypeAdapterFactory(SoliniaLootDropEntry.class));
    Gson gson = gsonbuilder.create();
    String jsonOutput = gson.toJson(lootdrops.values(), new TypeToken<List<SoliniaLootDrop>>() {
    }.getType());
    try {
        File file = new File(filePath);
        if (!file.exists())
            file.createNewFile();
        FileOutputStream fileOut = new FileOutputStream(file);
        OutputStreamWriter outWriter = new OutputStreamWriter(fileOut);
        outWriter.append(jsonOutput);
        outWriter.close();
        fileOut.close();
        System.out.println("Commited " + lootdrops.size() + " lootdrops");
    } catch (FileNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) ISoliniaLootDropEntryTypeAdapterFactory(com.solinia.solinia.Factories.ISoliniaLootDropEntryTypeAdapterFactory) TypeToken(com.google.gson.reflect.TypeToken) SoliniaLootDropEntry(com.solinia.solinia.Models.SoliniaLootDropEntry) FileOutputStream(java.io.FileOutputStream) FileNotFoundException(java.io.FileNotFoundException) Gson(com.google.gson.Gson) ISoliniaLootDrop(com.solinia.solinia.Interfaces.ISoliniaLootDrop) SoliniaLootDrop(com.solinia.solinia.Models.SoliniaLootDrop) OutputStreamWriter(java.io.OutputStreamWriter) IOException(java.io.IOException) File(java.io.File)

Aggregations

Gson (com.google.gson.Gson)2 GsonBuilder (com.google.gson.GsonBuilder)2 ISoliniaLootDropEntryTypeAdapterFactory (com.solinia.solinia.Factories.ISoliniaLootDropEntryTypeAdapterFactory)2 ISoliniaLootDrop (com.solinia.solinia.Interfaces.ISoliniaLootDrop)2 SoliniaLootDropEntry (com.solinia.solinia.Models.SoliniaLootDropEntry)2 FileNotFoundException (java.io.FileNotFoundException)2 TypeToken (com.google.gson.reflect.TypeToken)1 SoliniaLootDrop (com.solinia.solinia.Models.SoliniaLootDrop)1 BufferedReader (java.io.BufferedReader)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 FileReader (java.io.FileReader)1 IOException (java.io.IOException)1 OutputStreamWriter (java.io.OutputStreamWriter)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1