/* Swisscom Safe Connect Copyright (C) 2014 Swisscom This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program. If not, see <http://www.gnu.org/licenses/>. */ package com.swisscom.safeconnect.json; import android.util.Log; import com.swisscom.safeconnect.BuildConfig; import com.swisscom.safeconnect.utils.Config; import java.io.BufferedReader; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.util.List; public abstract class JsonParser<T> { public static String toJsonString(InputStream is) { // read the json InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr); String line = ""; StringBuilder sb = new StringBuilder(); try { while ((line = br.readLine()) != null) { sb.append(line).append("\n"); } } catch (IOException e) { if (BuildConfig.DEBUG) Log.e(Config.TAG, "error", e); } finally { try { if (br != null) { br.close(); } if (isr != null) { isr.close(); } if (is != null) { is.close(); } } catch (IOException e) { if (BuildConfig.DEBUG) Log.e(Config.TAG, "error", e); } } return sb.toString(); } protected abstract void parseJson(String jsonString); public abstract List<T> getListResult(); public abstract T getResult(); }