package org.topq.jsystem.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;

import android.util.Log;

/**
 * 
 * @author Bortman Limor
 * 
 */
public class ConfUtil {

	private Map<String, String> confMap = null;
	private static ConfUtil confUtil = null;
	private static final String TAG = "ConfUtil";
	private static final String CONFIG_FILE = "/data/conf.txt";

	/**
	 * Search for config file from the following properties: <br>
	 * LAUNCHER_ACTIVITY_FULL_CLASSNAME <br>
	 * TARGET_PACKAGE_ID <br>
	 * <br>
	 * For example: <br>
	 * LAUNCHER_ACTIVITY_FULL_CLASSNAME =
	 * com.gettaxi.android.activities.login.LoadingActivity <br>
	 * TARGET_PACKAGE_ID = com.gettaxi <br>
	 * 
	 * 
	 * 
	 * 
	 * @throws IOException
	 */
	private ConfUtil() throws IOException {

		confMap = new HashMap<String, String>();
		InputStream in = null;
		BufferedReader buffer = null;
		try {
			// init all the configuration
			File config = new File(CONFIG_FILE);
			if (!config.exists()) {
				String error = "No config file found: " + CONFIG_FILE;
				Log.e(TAG,error);
				throw new IOException(error);
			}
			in = new FileInputStream(config);

			InputStreamReader input = new InputStreamReader(in);
			buffer = new BufferedReader(input);
			String line = " ";

			while ((line = buffer.readLine()) != null) {
				confMap.put(line.split("=")[0].trim(), line.split("=")[1].trim());
			}

		} catch (IOException e) {
			Log.e(TAG, "Failed to open " + CONFIG_FILE + " " + e.getMessage());
			e.printStackTrace();
		} finally {
			if (null != in) {
				in.close();
			}
			if (null != buffer) {
				buffer.close();
			}
		}

	}

	public static ConfUtil getInstance() throws IOException {
		if (confUtil == null) {
			try {
				confUtil = new ConfUtil();
			} catch (IOException e) {
				Log.e(TAG, "Failed to Create confUtil  " + e.getMessage());
				throw e;
			}
		}
		return confUtil;
	}

	public String getConfigParameters(String paramName) {
		return confMap.get(paramName);
	}

}

@@ -1550,131 +1550,8 @@
 %09%7D%0A%0A
-%09%09%7D catch (IOException e) %7B%0A%09%09%09Log.e(TAG, %22Failed to open %22 + CONFIG_FILE + %22 %22 + e.getMessage());%0A%09%09%09e.printStackTrace();%0A
 %09%09%7D 

remove catch