package org.cocktailmolotov.partyplanner.io;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

import org.cocktailmolotov.partyplanner.dto.Cocktails;
import org.cocktailmolotov.partyplanner.dto.Ingredients;

import com.fasterxml.jackson.databind.ObjectMapper;

/**
 * Created by maxime on 11/02/16.
 */
public class CocktailLoader {

	static Loader LOADER = new Loader();
	public static Loader getLoader(){
		return LOADER;
	} 


	public static class Loader {
		private Loader() {
			// Nothing
		}

		final String COCKTAILS_URL = "/home/maxime/code/partyplanner/src/main/resources/cocktails.json";
		final String INGREDIENTS_URL = "/home/maxime/code/partyplanner/src/main/resources/ingredients.json";

		public File getCocktailsFile() throws IOException {
			return new File(COCKTAILS_URL);
		}

		public File getIngredientsFile() throws IOException {
			return new File(INGREDIENTS_URL);
		}
		
		public Cocktails loadCocktails() throws IOException{
			File file = getCocktailsFile();
			ObjectMapper om = new ObjectMapper();
			Cocktails cocktails = om.readValue(file, Cocktails.class);
			return cocktails;
		}
		
		public Ingredients loadIngredients() throws IOException{
			File file = getIngredientsFile();
			ObjectMapper om = new ObjectMapper();
			return om.readValue(file, Ingredients.class);
		}
	}
}
@@ -378,16 +378,30 @@
 der %7B%0A%0A%09
+final private 
 static L
@@ -429,16 +429,17 @@
 ader();%0A
+%0A
 %09public 
@@ -484,17 +484,16 @@
 ADER;%0A%09%7D
- 
 %0A%0A%0A%09publ
@@ -517,16 +517,70 @@
 oader %7B%0A
+%09%09final private ObjectMapper om = new ObjectMapper();%0A
 %09%09privat
@@ -611,24 +611,25 @@
 ng%0A%09%09%7D%0A%0A
+%0A
 %09%09final 
 String C
@@ -624,82 +624,88 @@
 nal 
-String COCKTAILS_URL = %22/home/maxime/code/partyplanner/src/main/resources/
+InputStream COCKTAILS_STREAM = getClass().getClassLoader().getResourceAsStream(%22
 cock
@@ -715,16 +715,17 @@
 ls.json%22
+)
 ;%0A%09%09fina
@@ -730,14 +730,19 @@
 nal 
-String
+InputStream
  ING
@@ -754,409 +754,144 @@
 NTS_
-URL = %22/home/maxime/code/partyplanner/src/main/resources/ingredients.json%22;%0A%0A%09%09public File getCocktailsFile() throws IOException %7B%0A%09%09%09return new File(COCKTAILS_URL);%0A%09%09%7D%0A%0A%09%09public File getIngredientsFile() throws IOException %7B%0A%09%09%09return new File(INGREDIENTS_URL);%0A%09%09%7D%0A%09%09%0A%09%09public Cocktails loadCocktails() throws IOException%7B%0A%09%09%09File file = getCocktailsFile();%0A%09%09%09ObjectMapper om = new ObjectMapper();
+STREAM = getClass().getClassLoader().getResourceAsStream(%22ingredients.json%22);%0A%0A%09%09%0A%09%09public Cocktails loadCocktails() throws IOException%7B
 %0A%09%09%09
@@ -925,20 +925,32 @@
 adValue(
-file
+COCKTAILS_STREAM
 , Cockta
@@ -1052,86 +1052,8 @@
 on%7B%0A
-%09%09%09File file = getIngredientsFile();%0A%09%09%09ObjectMapper om = new ObjectMapper();%0A
 %09%09%09r
@@ -1075,12 +1075,26 @@
 lue(
-file
+INGREDIENTS_STREAM
 , In

fix load resources