blob: b43c320b7771b84c93e67d79d1462313a7a3f2e5 [file] [log] [blame]
Nader Jawad8c1d7aa2023-03-02 15:59:11 -08001/*
2 * Copyright (C) 2023 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16#ifndef BUFFERUTILS_H_
17#define BUFFERUTILS_H_
18
19#include <jni.h>
20
21#include <vector>
22
23/**
24 * Helper method to load a java.nio.Buffer instance into a vector. This handles
25 * both direct and indirect buffers and promptly releases any critical arrays that
26 * have been retrieved in order to avoid potential jni exceptions due to interleaved
27 * jni calls between get/release primitive method invocations.
28 */
29std::vector<uint8_t> copyJavaNioBufferToVector(JNIEnv* env, jobject buffer, size_t size,
30 jboolean isDirect);
31
32#endif // BUFFERUTILS_H_