OLD | NEW |
1 /* | 1 /* |
2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
3 * Copyright (C) 2006-2017 eyeo GmbH | 3 * Copyright (C) 2006-2017 eyeo GmbH |
4 * | 4 * |
5 * Adblock Plus is free software: you can redistribute it and/or modify | 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 | 6 * it under the terms of the GNU General Public License version 3 as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
8 * | 8 * |
9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
13 * | 13 * |
14 * You should have received a copy of the GNU General Public License | 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/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
16 */ | 16 */ |
17 | 17 |
18 #include <string> | 18 #include <string> |
| 19 #include <sstream> |
| 20 #include <iostream> |
19 | 21 |
20 #include "Utils.h" | 22 #include "Utils.h" |
21 | 23 |
22 // precached in JNI_OnLoad and released in JNI_OnUnload | 24 // precached in JNI_OnLoad and released in JNI_OnUnload |
23 JniGlobalReference<jclass>* arrayListClass; | 25 JniGlobalReference<jclass>* arrayListClass; |
24 jmethodID arrayListCtor; | 26 jmethodID arrayListCtor; |
25 | 27 |
26 JniGlobalReference<jclass>* filterClass; | 28 JniGlobalReference<jclass>* filterClass; |
27 jmethodID filterCtor; | 29 jmethodID filterCtor; |
28 | 30 |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 return std::string(); | 93 return std::string(); |
92 } | 94 } |
93 | 95 |
94 const char* cStr = env->GetStringUTFChars(str, 0); | 96 const char* cStr = env->GetStringUTFChars(str, 0); |
95 std::string ret(cStr); | 97 std::string ret(cStr); |
96 env->ReleaseStringUTFChars(str, cStr); | 98 env->ReleaseStringUTFChars(str, cStr); |
97 | 99 |
98 return ret; | 100 return ret; |
99 } | 101 } |
100 | 102 |
| 103 std::string JniStdStreamToStdString(std::istream *in) |
| 104 { |
| 105 std::string ret; |
| 106 char buffer[1024]; |
| 107 while (in->read(buffer, sizeof(buffer))) |
| 108 ret.append(buffer, sizeof(buffer)); |
| 109 ret.append(buffer, in->gcount()); |
| 110 return ret; |
| 111 } |
| 112 |
101 jstring JniStdStringToJava(JNIEnv* env, std::string str) | 113 jstring JniStdStringToJava(JNIEnv* env, std::string str) |
102 { | 114 { |
103 return env->NewStringUTF(str.c_str()); | 115 return env->NewStringUTF(str.c_str()); |
104 } | 116 } |
105 | 117 |
106 jobject NewJniArrayList(JNIEnv* env) | 118 jobject NewJniArrayList(JNIEnv* env) |
107 { | 119 { |
108 return env->NewObject(arrayListClass->Get(), arrayListCtor); | 120 return env->NewObject(arrayListClass->Get(), arrayListCtor); |
109 } | 121 } |
110 | 122 |
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
191 const AdblockPlus::SubscriptionPtr& subscription) | 203 const AdblockPlus::SubscriptionPtr& subscription) |
192 { | 204 { |
193 return NewJniObject(env, subscription, subscriptionClass->Get(), subscriptionC
tor); | 205 return NewJniObject(env, subscription, subscriptionClass->Get(), subscriptionC
tor); |
194 } | 206 } |
195 | 207 |
196 jobject NewJniNotification(JNIEnv* env, | 208 jobject NewJniNotification(JNIEnv* env, |
197 const AdblockPlus::NotificationPtr& notification) | 209 const AdblockPlus::NotificationPtr& notification) |
198 { | 210 { |
199 return NewJniObject(env, notification, notificationClass->Get(), notificationC
tor); | 211 return NewJniObject(env, notification, notificationClass->Get(), notificationC
tor); |
200 } | 212 } |
OLD | NEW |