| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef BASE_ANDROID_JNI_ARRAY_H_ | |
| 6 #define BASE_ANDROID_JNI_ARRAY_H_ | |
| 7 | |
| 8 #include <jni.h> | |
| 9 #include <string> | |
| 10 #include <vector> | |
| 11 | |
| 12 #include "base/android/scoped_java_ref.h" | |
| 13 #include "base/basictypes.h" | |
| 14 #include "base/strings/string16.h" | |
| 15 | |
| 16 namespace base { | |
| 17 namespace android { | |
| 18 | |
| 19 // Returns a new Java byte array converted from the given bytes array. | |
| 20 BASE_EXPORT ScopedJavaLocalRef<jbyteArray> ToJavaByteArray( | |
| 21 JNIEnv* env, const uint8* bytes, size_t len); | |
| 22 | |
| 23 // Returns a new Java int array converted from the given int array. | |
| 24 BASE_EXPORT ScopedJavaLocalRef<jintArray> ToJavaIntArray( | |
| 25 JNIEnv* env, const int* ints, size_t len); | |
| 26 | |
| 27 BASE_EXPORT ScopedJavaLocalRef<jintArray> ToJavaIntArray( | |
| 28 JNIEnv* env, const std::vector<int>& ints); | |
| 29 | |
| 30 // Returns a new Java long array converted from the given int64 array. | |
| 31 BASE_EXPORT ScopedJavaLocalRef<jlongArray> ToJavaLongArray( | |
| 32 JNIEnv* env, const int64* longs, size_t len); | |
| 33 | |
| 34 BASE_EXPORT ScopedJavaLocalRef<jlongArray> ToJavaLongArray( | |
| 35 JNIEnv* env, const std::vector<int64>& longs); | |
| 36 | |
| 37 // Returns a array of Java byte array converted from |v|. | |
| 38 BASE_EXPORT ScopedJavaLocalRef<jobjectArray> ToJavaArrayOfByteArray( | |
| 39 JNIEnv* env, const std::vector<std::string>& v); | |
| 40 | |
| 41 BASE_EXPORT ScopedJavaLocalRef<jobjectArray> ToJavaArrayOfStrings( | |
| 42 JNIEnv* env, const std::vector<std::string>& v); | |
| 43 | |
| 44 BASE_EXPORT ScopedJavaLocalRef<jobjectArray> ToJavaArrayOfStrings( | |
| 45 JNIEnv* env, const std::vector<string16>& v); | |
| 46 | |
| 47 // Converts a Java string array to a native array. | |
| 48 BASE_EXPORT void AppendJavaStringArrayToStringVector( | |
| 49 JNIEnv* env, | |
| 50 jobjectArray array, | |
| 51 std::vector<string16>* out); | |
| 52 | |
| 53 BASE_EXPORT void AppendJavaStringArrayToStringVector( | |
| 54 JNIEnv* env, | |
| 55 jobjectArray array, | |
| 56 std::vector<std::string>* out); | |
| 57 | |
| 58 // Appends the Java bytes in |bytes_array| onto the end of |out|. | |
| 59 BASE_EXPORT void AppendJavaByteArrayToByteVector( | |
| 60 JNIEnv* env, | |
| 61 jbyteArray byte_array, | |
| 62 std::vector<uint8>* out); | |
| 63 | |
| 64 // Replaces the content of |out| with the Java bytes in |bytes_array|. | |
| 65 BASE_EXPORT void JavaByteArrayToByteVector( | |
| 66 JNIEnv* env, | |
| 67 jbyteArray byte_array, | |
| 68 std::vector<uint8>* out); | |
| 69 | |
| 70 // Replaces the content of |out| with the Java ints in |int_array|. | |
| 71 BASE_EXPORT void JavaIntArrayToIntVector( | |
| 72 JNIEnv* env, | |
| 73 jintArray int_array, | |
| 74 std::vector<int>* out); | |
| 75 | |
| 76 // Replaces the content of |out| with the Java longs in |long_array|. | |
| 77 BASE_EXPORT void JavaLongArrayToLongVector( | |
| 78 JNIEnv* env, | |
| 79 jlongArray long_array, | |
| 80 std::vector<jlong>* out); | |
| 81 | |
| 82 // Replaces the content of |out| with the Java floats in |float_array|. | |
| 83 BASE_EXPORT void JavaFloatArrayToFloatVector( | |
| 84 JNIEnv* env, | |
| 85 jfloatArray float_array, | |
| 86 std::vector<float>* out); | |
| 87 | |
| 88 // Assuming |array| is an byte[][] (array of byte arrays), replaces the | |
| 89 // content of |out| with the corresponding vector of strings. No UTF-8 | |
| 90 // conversion is performed. | |
| 91 BASE_EXPORT void JavaArrayOfByteArrayToStringVector( | |
| 92 JNIEnv* env, | |
| 93 jobjectArray array, | |
| 94 std::vector<std::string>* out); | |
| 95 | |
| 96 } // namespace android | |
| 97 } // namespace base | |
| 98 | |
| 99 #endif // BASE_ANDROID_JNI_ARRAY_H_ | |
| OLD | NEW |