koodikoe.database.ConfigReader.java Source code

Java tutorial

Introduction

Here is the source code for koodikoe.database.ConfigReader.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package koodikoe.database;

import com.google.gson.Gson;
import com.google.gson.stream.JsonReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 *
 * @author kari
 */
public final class ConfigReader {

    public static final Credentials getCredentials() {
        Gson g = new Gson();
        InputStream is = ConfigReader.class.getResourceAsStream("/dbConfig.json");
        if (is == null) {
            return new Credentials("test", "bar");
        }
        JsonReader reader = new JsonReader(new InputStreamReader(is));
        Credentials creds = g.fromJson(reader, Credentials.class);
        return creds;
    }
}