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 #ifndef BASE_ANDROID_JNI_ARRAY_H_ | 5 #ifndef BASE_ANDROID_JNI_ARRAY_H_ |
6 #define BASE_ANDROID_JNI_ARRAY_H_ | 6 #define BASE_ANDROID_JNI_ARRAY_H_ |
7 | 7 |
8 #include <jni.h> | 8 #include <jni.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <stdint.h> | 10 #include <stdint.h> |
11 #include <string> | 11 #include <string> |
12 #include <vector> | 12 #include <vector> |
13 | 13 |
14 #include "base/android/scoped_java_ref.h" | 14 #include "base/android/scoped_java_ref.h" |
15 #include "base/strings/string16.h" | 15 #include "base/strings/string16.h" |
16 | 16 |
17 namespace base { | 17 namespace base { |
18 namespace android { | 18 namespace android { |
19 | 19 |
20 // Returns a new Java byte array converted from the given bytes array. | 20 // Returns a new Java byte array converted from the given bytes array. |
21 BASE_EXPORT ScopedJavaLocalRef<jbyteArray> ToJavaByteArray(JNIEnv* env, | 21 BASE_EXPORT ScopedJavaLocalRef<jbyteArray> ToJavaByteArray(JNIEnv* env, |
22 const uint8_t* bytes, | 22 const uint8_t* bytes, |
23 size_t len); | 23 size_t len); |
24 | 24 |
25 BASE_EXPORT ScopedJavaLocalRef<jbyteArray> ToJavaByteArray( | 25 BASE_EXPORT ScopedJavaLocalRef<jbyteArray> ToJavaByteArray( |
26 JNIEnv* env, | 26 JNIEnv* env, |
27 const std::vector<uint8_t>& bytes); | 27 const std::vector<uint8_t>& bytes); |
28 | 28 |
| 29 // Returns a new Java boolean array converted from the given bool array. |
| 30 BASE_EXPORT ScopedJavaLocalRef<jbooleanArray> |
| 31 ToJavaBooleanArray(JNIEnv* env, const bool* bools, size_t len); |
| 32 |
29 // Returns a new Java int array converted from the given int array. | 33 // Returns a new Java int array converted from the given int array. |
30 BASE_EXPORT ScopedJavaLocalRef<jintArray> ToJavaIntArray( | 34 BASE_EXPORT ScopedJavaLocalRef<jintArray> ToJavaIntArray( |
31 JNIEnv* env, const int* ints, size_t len); | 35 JNIEnv* env, const int* ints, size_t len); |
32 | 36 |
33 BASE_EXPORT ScopedJavaLocalRef<jintArray> ToJavaIntArray( | 37 BASE_EXPORT ScopedJavaLocalRef<jintArray> ToJavaIntArray( |
34 JNIEnv* env, const std::vector<int>& ints); | 38 JNIEnv* env, const std::vector<int>& ints); |
35 | 39 |
36 // Returns a new Java long array converted from the given int64_t array. | 40 // Returns a new Java long array converted from the given int64_t array. |
37 BASE_EXPORT ScopedJavaLocalRef<jlongArray> ToJavaLongArray(JNIEnv* env, | 41 BASE_EXPORT ScopedJavaLocalRef<jlongArray> ToJavaLongArray(JNIEnv* env, |
38 const int64_t* longs, | 42 const int64_t* longs, |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
74 // Appends the Java bytes in |bytes_array| onto the end of |out|. | 78 // Appends the Java bytes in |bytes_array| onto the end of |out|. |
75 BASE_EXPORT void AppendJavaByteArrayToByteVector(JNIEnv* env, | 79 BASE_EXPORT void AppendJavaByteArrayToByteVector(JNIEnv* env, |
76 jbyteArray byte_array, | 80 jbyteArray byte_array, |
77 std::vector<uint8_t>* out); | 81 std::vector<uint8_t>* out); |
78 | 82 |
79 // Replaces the content of |out| with the Java bytes in |bytes_array|. | 83 // Replaces the content of |out| with the Java bytes in |bytes_array|. |
80 BASE_EXPORT void JavaByteArrayToByteVector(JNIEnv* env, | 84 BASE_EXPORT void JavaByteArrayToByteVector(JNIEnv* env, |
81 jbyteArray byte_array, | 85 jbyteArray byte_array, |
82 std::vector<uint8_t>* out); | 86 std::vector<uint8_t>* out); |
83 | 87 |
| 88 // Replaces the content of |out| with the Java booleans in |boolean_array|. |
| 89 BASE_EXPORT void JavaBooleanArrayToBoolVector(JNIEnv* env, |
| 90 jbooleanArray boolean_array, |
| 91 std::vector<bool>* out); |
| 92 |
84 // Replaces the content of |out| with the Java ints in |int_array|. | 93 // Replaces the content of |out| with the Java ints in |int_array|. |
85 BASE_EXPORT void JavaIntArrayToIntVector( | 94 BASE_EXPORT void JavaIntArrayToIntVector( |
86 JNIEnv* env, | 95 JNIEnv* env, |
87 jintArray int_array, | 96 jintArray int_array, |
88 std::vector<int>* out); | 97 std::vector<int>* out); |
89 | 98 |
90 // Replaces the content of |out| with the Java longs in |long_array|. | 99 // Replaces the content of |out| with the Java longs in |long_array|. |
91 BASE_EXPORT void JavaLongArrayToInt64Vector(JNIEnv* env, | 100 BASE_EXPORT void JavaLongArrayToInt64Vector(JNIEnv* env, |
92 jlongArray long_array, | 101 jlongArray long_array, |
93 std::vector<int64_t>* out); | 102 std::vector<int64_t>* out); |
(...skipping 22 matching lines...) Expand all Loading... |
116 // contents of |out| with the corresponding vectors of ints. | 125 // contents of |out| with the corresponding vectors of ints. |
117 BASE_EXPORT void JavaArrayOfIntArrayToIntVector( | 126 BASE_EXPORT void JavaArrayOfIntArrayToIntVector( |
118 JNIEnv* env, | 127 JNIEnv* env, |
119 jobjectArray array, | 128 jobjectArray array, |
120 std::vector<std::vector<int>>* out); | 129 std::vector<std::vector<int>>* out); |
121 | 130 |
122 } // namespace android | 131 } // namespace android |
123 } // namespace base | 132 } // namespace base |
124 | 133 |
125 #endif // BASE_ANDROID_JNI_ARRAY_H_ | 134 #endif // BASE_ANDROID_JNI_ARRAY_H_ |
OLD | NEW |