Example usage for com.google.gson JsonStreamParser JsonStreamParser

List of usage examples for com.google.gson JsonStreamParser JsonStreamParser

Introduction

In this page you can find the example usage for com.google.gson JsonStreamParser JsonStreamParser.

Prototype

public JsonStreamParser(Reader reader) 

Source Link

Usage

From source file:pl.projewski.game.polan.server.data.ServerData.java

public void loadProductDefinitionsFromGsonFile(String filename) {
    productDefinitionMap = new HashMap();
    Gson gson = GSonUtil.getGSon();/* ww w. j  a va2s  .  c om*/
    InputStreamReader reader = null;
    try {
        final File file = new File(filename);
        if (file.exists()) {
            reader = new InputStreamReader(new FileInputStream(file));
            JsonStreamParser parser = new JsonStreamParser(reader);
            while (parser.hasNext()) {
                ProductDefinition pd = gson.fromJson(parser.next(), ProductDefinition.class);
                productDefinitionMap.put(pd.getName(), pd);
                LOG.debug("Loaded product " + pd.getName());
            }
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(ServerData.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        IOUtils.closeQuietly(reader);
    }

}

From source file:pl.projewski.game.polan.server.data.ServerData.java

public void loadBiomeDefinitionsFromGsonFile(String filename) {
    biomeDefinitionList = new ArrayList();
    Gson gson = GSonUtil.getGSon();//ww w .j  ava  2  s .  c  o  m
    InputStreamReader reader = null;
    try {
        final File file = new File(filename);
        if (file.exists()) {
            reader = new InputStreamReader(new FileInputStream(file));
            JsonStreamParser parser = new JsonStreamParser(reader);
            while (parser.hasNext()) {
                BiomeDefinition bd = gson.fromJson(parser.next(), BiomeDefinition.class);
                biomeDefinitionList.add(bd);
                LOG.debug("Loaded biome " + bd.getName());
            }
        }
    } catch (FileNotFoundException ex) {
        Logger.getLogger(ServerData.class.getName()).log(Level.SEVERE, null, ex);
    } finally {
        IOUtils.closeQuietly(reader);
    }
}