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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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(), NULL); |
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 jsize array_len = env->GetArrayLength(int_array.obj()); |
| 249 jint* ints = env->GetIntArrayElements(int_array.obj(), nullptr); |
| 250 std::vector<int> vector_ints = out->at(i); |
| 251 vector_ints.resize(array_len); |
| 252 for (jsize j = 0; j < array_len; ++j) { |
| 253 vector_ints[j] = static_cast<int>(ints[j]); |
| 254 } |
| 255 |
| 256 (*out)[i] = vector_ints; |
| 257 env->ReleaseIntArrayElements(int_array.obj(), ints, JNI_ABORT); |
| 258 } |
| 259 } |
| 260 |
238 } // namespace android | 261 } // namespace android |
239 } // namespace base | 262 } // namespace base |
OLD | NEW |