comparison Plugin/JavaString.cpp @ 7:b14ed1ea3a23

reorganization
author Sebastien Jodogne <s.jodogne@gmail.com>
date Thu, 19 Oct 2023 11:14:45 +0200
parents
children 1c407ba1d311
comparison
equal deleted inserted replaced
6:709e5347a390 7:b14ed1ea3a23
1 /**
2 * SPDX-FileCopyrightText: 2023 Sebastien Jodogne, UCLouvain, Belgium
3 * SPDX-License-Identifier: GPL-3.0-or-later
4 */
5
6 /**
7 * Java plugin for Orthanc
8 * Copyright (C) 2023 Sebastien Jodogne, UCLouvain, Belgium
9 *
10 * This program is free software: you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License as
12 * published by the Free Software Foundation, either version 3 of the
13 * License, or (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful, but
16 * WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <http://www.gnu.org/licenses/>.
22 **/
23
24
25 #include "JavaString.h"
26
27 #include <stdexcept>
28
29
30 JavaString::JavaString(JNIEnv* env,
31 jstring javaStr) :
32 env_(env),
33 javaStr_(javaStr)
34 {
35 if (env == NULL ||
36 javaStr == NULL)
37 {
38 throw std::runtime_error("Null pointer");
39 }
40
41 cStr_ = env_->GetStringUTFChars(javaStr_, &isCopy_);
42 if (cStr_ == NULL)
43 {
44 throw std::runtime_error("Cannot read string");
45 }
46 }
47
48
49 JavaString::~JavaString()
50 {
51 /**
52 * "The ReleaseString-Chars call is necessary whether
53 * GetStringChars has set isCopy to JNI_TRUE or JNI_FALSE."
54 * https://stackoverflow.com/a/5863081
55 **/
56 env_->ReleaseStringUTFChars(javaStr_, cStr_);
57 }