| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | |
| 3 * Copyright (C) 2006-present eyeo GmbH | |
| 4 * | |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | |
| 6 * it under the terms of the GNU General Public License version 3 as | |
| 7 * published by the Free Software Foundation. | |
| 8 * | |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 12 * GNU General Public License for more details. | |
| 13 * | |
| 14 * You should have received a copy of the GNU General Public License | |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | |
| 16 */ | |
| 17 | |
| 18 package org.adblockplus.libadblockplus.android; | |
| 19 | |
| 20 import java.io.BufferedReader; | |
| 21 import java.io.IOException; | |
| 22 import java.io.InputStream; | |
| 23 import java.io.InputStreamReader; | |
| 24 import java.util.List; | |
| 25 | |
| 26 import org.json.JSONArray; | |
| 27 | |
| 28 import android.content.Context; | |
| 29 | |
| 30 public final class Utils | |
| 31 { | |
| 32 private Utils() | |
| 33 { | |
| 34 // | |
| 35 } | |
| 36 | |
| 37 public static String getTag(final Class<?> clazz) | |
| 38 { | |
| 39 return clazz.getSimpleName(); | |
| 40 } | |
| 41 | |
| 42 public static String stringListToJsonArray(List<String> list) | |
| 43 { | |
| 44 JSONArray array = new JSONArray(); | |
| 45 | |
| 46 if (list != null) | |
| 47 { | |
| 48 for (String eachString : list) | |
| 49 { | |
| 50 if (eachString != null) | |
| 51 { | |
| 52 array.put(eachString); | |
| 53 } | |
| 54 } | |
| 55 } | |
| 56 | |
| 57 return array.toString(); | |
| 58 } | |
| 59 | |
| 60 public static String readAssetAsString(Context context, String filename) throw
s IOException | |
| 61 { | |
| 62 BufferedReader in = null; | |
| 63 try | |
| 64 { | |
| 65 StringBuilder buf = new StringBuilder(); | |
| 66 InputStream is = context.getAssets().open(filename); | |
| 67 in = new BufferedReader(new InputStreamReader(is)); | |
| 68 | |
| 69 String str; | |
| 70 boolean isFirst = true; | |
| 71 while ((str = in.readLine()) != null) | |
| 72 { | |
| 73 if (isFirst) | |
| 74 { | |
| 75 isFirst = false; | |
| 76 } | |
| 77 else | |
| 78 { | |
| 79 buf.append('\n'); | |
| 80 } | |
| 81 buf.append(str); | |
| 82 } | |
| 83 return buf.toString(); | |
| 84 } | |
| 85 finally | |
| 86 { | |
| 87 if (in != null) | |
| 88 { | |
| 89 try | |
| 90 { | |
| 91 in.close(); | |
| 92 } | |
| 93 catch (IOException e) | |
| 94 { | |
| 95 // ignored | |
| 96 } | |
| 97 } | |
| 98 } | |
| 99 } | |
| 100 | |
| 101 public static String getUrlWithoutParams(String urlWithParams) | |
| 102 { | |
| 103 if (urlWithParams == null) | |
| 104 { | |
| 105 throw new IllegalArgumentException("URL can't be null"); | |
| 106 } | |
| 107 | |
| 108 int pos = urlWithParams.indexOf("?"); | |
| 109 return (pos >= 0 ? urlWithParams.substring(0, pos) : urlWithParams); | |
| 110 } | |
| 111 } | |
| OLD | NEW |