OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "base/android/jni_array.h" | 5 #include "base/android/jni_array.h" |
6 | 6 |
7 #include "base/android/jni_android.h" | 7 #include "base/android/jni_android.h" |
8 #include "base/android/jni_string.h" | 8 #include "base/android/jni_string.h" |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 | 10 |
(...skipping 211 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
222 jobjectArray array, | 222 jobjectArray array, |
223 std::vector<std::string>* out) { | 223 std::vector<std::string>* out) { |
224 DCHECK(out); | 224 DCHECK(out); |
225 size_t len = SafeGetArrayLength(env, array); | 225 size_t len = SafeGetArrayLength(env, array); |
226 out->resize(len); | 226 out->resize(len); |
227 for (size_t i = 0; i < len; ++i) { | 227 for (size_t i = 0; i < len; ++i) { |
228 ScopedJavaLocalRef<jbyteArray> bytes_array( | 228 ScopedJavaLocalRef<jbyteArray> bytes_array( |
229 env, static_cast<jbyteArray>( | 229 env, static_cast<jbyteArray>( |
230 env->GetObjectArrayElement(array, i))); | 230 env->GetObjectArrayElement(array, i))); |
231 jsize bytes_len = env->GetArrayLength(bytes_array.obj()); | 231 jsize bytes_len = env->GetArrayLength(bytes_array.obj()); |
232 jbyte* bytes = env->GetByteArrayElements(bytes_array.obj(), NULL); | 232 jbyte* bytes = env->GetByteArrayElements(bytes_array.obj(), nullptr); |
233 (*out)[i].assign(reinterpret_cast<const char*>(bytes), bytes_len); | 233 (*out)[i].assign(reinterpret_cast<const char*>(bytes), bytes_len); |
234 env->ReleaseByteArrayElements(bytes_array.obj(), bytes, JNI_ABORT); | 234 env->ReleaseByteArrayElements(bytes_array.obj(), bytes, JNI_ABORT); |
235 } | 235 } |
236 } | 236 } |
237 | 237 |
238 void JavaArrayOfIntArrayToIntVector( | |
239 JNIEnv* env, | |
240 jobjectArray array, | |
241 std::vector<std::vector<int>>* out) { | |
242 DCHECK(out); | |
243 size_t len = SafeGetArrayLength(env, array); | |
244 out->resize(len); | |
245 for (size_t i = 0; i < len; ++i) { | |
246 ScopedJavaLocalRef<jintArray> int_array( | |
247 env, static_cast<jintArray>(env->GetObjectArrayElement(array, i))); | |
248 jint* ints = env->GetIntArrayElements(int_array.obj(), nullptr); | |
Dmitry Skiba
2015/10/30 16:46:19
Hmm, do we really need to get 'ints' here? It does
Theresa
2015/10/30 17:01:15
It's used to release the int array elements on lin
Dmitry Skiba
2015/10/30 17:17:32
Yes, but 'ints' is not read from. For example in t
Theresa
2015/10/30 17:25:28
I included this code because a new jintArray is cr
Dmitry Skiba
2015/10/30 17:37:26
There are two ways of accessing array elements: Ge
| |
249 JavaIntArrayToIntVector(env, int_array.obj(), &((*out)[i])); | |
250 env->ReleaseIntArrayElements(int_array.obj(), ints, JNI_ABORT); | |
251 } | |
252 } | |
253 | |
238 } // namespace android | 254 } // namespace android |
239 } // namespace base | 255 } // namespace base |
OLD | NEW |