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 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 return; | 156 return; |
157 size_t len = SafeGetArrayLength(env, byte_array); | 157 size_t len = SafeGetArrayLength(env, byte_array); |
158 if (!len) | 158 if (!len) |
159 return; | 159 return; |
160 size_t back = out->size(); | 160 size_t back = out->size(); |
161 out->resize(back + len); | 161 out->resize(back + len); |
162 env->GetByteArrayRegion(byte_array, 0, len, | 162 env->GetByteArrayRegion(byte_array, 0, len, |
163 reinterpret_cast<int8*>(&(*out)[back])); | 163 reinterpret_cast<int8*>(&(*out)[back])); |
164 } | 164 } |
165 | 165 |
| 166 void AppendJavaLongArrayToLongVector(JNIEnv* env, |
| 167 jlongArray long_array, |
| 168 std::vector<int64_t>* out) { |
| 169 DCHECK(out); |
| 170 if (!long_array) |
| 171 return; |
| 172 jsize len = env->GetArrayLength(long_array); |
| 173 jlong* longs = env->GetLongArrayElements(long_array, NULL); |
| 174 out->insert(out->end(), longs, longs + len); |
| 175 env->ReleaseLongArrayElements(long_array, longs, JNI_ABORT); |
| 176 } |
| 177 |
166 void JavaByteArrayToByteVector(JNIEnv* env, | 178 void JavaByteArrayToByteVector(JNIEnv* env, |
167 jbyteArray byte_array, | 179 jbyteArray byte_array, |
168 std::vector<uint8>* out) { | 180 std::vector<uint8>* out) { |
169 DCHECK(out); | 181 DCHECK(out); |
170 DCHECK(byte_array); | 182 DCHECK(byte_array); |
171 out->clear(); | 183 out->clear(); |
172 AppendJavaByteArrayToByteVector(env, byte_array, out); | 184 AppendJavaByteArrayToByteVector(env, byte_array, out); |
173 } | 185 } |
174 | 186 |
175 void JavaIntArrayToIntVector(JNIEnv* env, | 187 void JavaIntArrayToIntVector(JNIEnv* env, |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
220 env->GetObjectArrayElement(array, i))); | 232 env->GetObjectArrayElement(array, i))); |
221 jsize bytes_len = env->GetArrayLength(bytes_array.obj()); | 233 jsize bytes_len = env->GetArrayLength(bytes_array.obj()); |
222 jbyte* bytes = env->GetByteArrayElements(bytes_array.obj(), NULL); | 234 jbyte* bytes = env->GetByteArrayElements(bytes_array.obj(), NULL); |
223 (*out)[i].assign(reinterpret_cast<const char*>(bytes), bytes_len); | 235 (*out)[i].assign(reinterpret_cast<const char*>(bytes), bytes_len); |
224 env->ReleaseByteArrayElements(bytes_array.obj(), bytes, JNI_ABORT); | 236 env->ReleaseByteArrayElements(bytes_array.obj(), bytes, JNI_ABORT); |
225 } | 237 } |
226 } | 238 } |
227 | 239 |
228 } // namespace android | 240 } // namespace android |
229 } // namespace base | 241 } // namespace base |
OLD | NEW |