OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/android/scoped_java_ref.h" | 9 #include "base/android/scoped_java_ref.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
11 | 11 |
12 namespace base { | 12 namespace base { |
13 namespace android { | 13 namespace android { |
14 | 14 |
15 jbyteArray ToJavaByteArray(JNIEnv* env, | 15 jbyteArray ToJavaByteArray(JNIEnv* env, |
16 const unsigned char* bytes, | 16 const unsigned char* bytes, |
17 size_t len) { | 17 size_t len) { |
18 jbyteArray byte_array = env->NewByteArray(len); | 18 jbyteArray byte_array = env->NewByteArray(len); |
19 CheckException(env); | 19 CheckException(env); |
20 CHECK(byte_array); | 20 DCHECK(byte_array); |
21 | 21 |
22 jbyte* elements = env->GetByteArrayElements(byte_array, NULL); | 22 jbyte* elements = env->GetByteArrayElements(byte_array, NULL); |
23 memcpy(elements, bytes, len); | 23 memcpy(elements, bytes, len); |
24 env->ReleaseByteArrayElements(byte_array, elements, 0); | 24 env->ReleaseByteArrayElements(byte_array, elements, 0); |
25 CheckException(env); | 25 CheckException(env); |
26 | 26 |
27 return byte_array; | 27 return byte_array; |
28 } | 28 } |
29 | 29 |
30 jobjectArray ToJavaArrayOfByteArray(JNIEnv* env, | 30 jobjectArray ToJavaArrayOfByteArray(JNIEnv* env, |
(...skipping 21 matching lines...) Expand all Loading... |
52 for (size_t i = 0; i < v.size(); ++i) { | 52 for (size_t i = 0; i < v.size(); ++i) { |
53 ScopedJavaLocalRef<jstring> item(env, | 53 ScopedJavaLocalRef<jstring> item(env, |
54 ConvertUTF8ToJavaString(env, v[i])); | 54 ConvertUTF8ToJavaString(env, v[i])); |
55 env->SetObjectArrayElement(joa, i, item.obj()); | 55 env->SetObjectArrayElement(joa, i, item.obj()); |
56 } | 56 } |
57 return joa; | 57 return joa; |
58 } | 58 } |
59 | 59 |
60 } // namespace android | 60 } // namespace android |
61 } // namespace base | 61 } // namespace base |
OLD | NEW |