automatic save file creation

pull/369/merge
Justin Richer 2013-06-26 15:18:44 -04:00
parent 98d917f3b9
commit 3b3715ff91
1 changed files with 11 additions and 2 deletions

View File

@ -104,10 +104,15 @@ public class JsonFileRegisteredClientService implements RegisteredClientService
}
/**
* Sync this file out to disk.
* Sync the map of clients out to disk.
*/
private void write() {
try {
if (!file.exists()) {
// create a new file
logger.info("Creating saved clients list in " + file);
file.createNewFile();
}
FileWriter out = new FileWriter(file);
gson.toJson(clients, new TypeToken<Map<String, RegisteredClient>>(){}.getType(), out);
@ -126,6 +131,10 @@ public class JsonFileRegisteredClientService implements RegisteredClientService
*/
private void load() {
try {
if (!file.exists()) {
logger.info("No sved clients file found in " + file);
return;
}
FileReader in = new FileReader(file);
clients = gson.fromJson(in, new TypeToken<Map<String, RegisteredClient>>(){}.getType());