JNI 문자열 처리 함수

From Evernote:

JNI 문자열 처리 함수

Clipped from: http://docs.oracle.com/javase/7/docs/technotes/guides/jni/spec/functions.html#string_operations

문자열 생성

jstring NewString(JNIEnv *env, const jchar *unicodeChars, jsize len);
Constructs a new java.lang.String object from an array of Unicode characters.
PARAMETERS:
  • env: the JNI interface pointer.
  • unicodeChars: pointer to a Unicode string.
  • len: length of the Unicode string.

RETURNS:
Returns a Java string object, or NULL if the string cannot be constructed.
THROWS:
OutOfMemoryError: if the system runs out of memory.


문자열의 길이
jsize GetStringLength(JNIEnv *env, jstring string);
Returns the length (the count of Unicode characters) of a Java string.


PARAMETERS:
  • env: the JNI interface pointer.
  • string: a Java string object.

RETURNS:
Returns the length of the Java string.


문자열 가져오기
const jchar * GetStringChars(JNIEnv *env, jstring string, jboolean *isCopy);
Returns a pointer to the array of Unicode characters of the string. This pointer is valid until ReleaseStringchars() is called.

If isCopy is not NULL, then *isCopy is set to JNI_TRUE if a copy is made; or it is set to JNI_FALSE if no copy is made.
PARAMETERS:

  • env: the JNI interface pointer.
  • string: a Java string object.
  • isCopy: a pointer to a boolean.

RETURNS:
Returns a pointer to a Unicode string, or NULL if the operation fails.


문자열 메모리 해제
void ReleaseStringChars(JNIEnv *env, jstring string, const jchar *chars);
Informs the VM that the native code no longer needs access to chars. The chars argument is a pointer obtained from string using GetStringChars().
PARAMETERS:

  • env: the JNI interface pointer.
  • string: a Java string object.
  • chars: a pointer to a Unicode string.


문자열 생성 (UTF-8)
jstring NewStringUTF(JNIEnv *env, const char *bytes);
Constructs a new java.lang.String object from an array of characters in modified UTF-8 encoding.
PARAMETERS:

  • env: the JNI interface pointer.
  • bytes: the pointer to a modified UTF-8 string.

RETURNS:
Returns a Java string object, or NULL if the string cannot be constructed.
THROWS:
OutOfMemoryError: if the system runs out of memory.


문자열의 길이 (UTF-8)
jsize GetStringUTFLength(JNIEnv *env, jstring string);
Returns the length in bytes of the modified UTF-8 representation of a string.
PARAMETERS:
  • env: the JNI interface pointer.
  • string: a Java string object.

RETURNS:
Returns the UTF-8 length of the string.


문자열 가져오기 (UTF-8)
const char * GetStringUTFChars(JNIEnv *env, jstring string, jboolean *isCopy);
Returns a pointer to an array of bytes representing the string in modified UTF-8 encoding. This array is valid until it is released by ReleaseStringUTFChars().
If isCopy is not NULL, then *isCopy is set to JNI_TRUE if a copy is made; or it is set to JNI_FALSE if no copy is made.
PARAMETERS:
  • env: the JNI interface pointer.
  • string: a Java string object.
  • isCopy: a pointer to a boolean.

RETURNS:
Returns a pointer to a modified UTF-8 string, or NULL if the operation fails.


문자열 메모리 해제 (UTF-8)
void ReleaseStringUTFChars(JNIEnv *env, jstring string, const char *utf);
Informs the VM that the native code no longer needs access to utf. The utf argument is a pointer derived from string using GetStringUTFChars().
PARAMETERS:
  • env: the JNI interface pointer.
  • string: a Java string object.
  • utf: a pointer to a modified UTF-8 string.

부분 문자열 가져오기

void GetStringRegion(JNIEnv *env, jstring str, jsize start, jsize len, jchar *buf);
Copies len number of Unicode characters beginning at offset start to the given buffer buf.
THROWS:
StringIndexOutOfBoundsException on index overflow.


부분 문자열 가져오기 (UTF-8)
void GetStringUTFRegion(JNIEnv *env, jstring str, jsize start, jsize len, char *buf);
Translates len number of Unicode characters beginning at offset start into modified UTF-8 encoding and place the result in the given buffer buf.
THROWS:
StringIndexOutOfBoundsException on index overflow.



문자열 가져오기 / 해제하기
const jchar * GetStringCritical(JNIEnv *env, jstring string, jboolean *isCopy);
void ReleaseStringCritical(JNIEnv *env, jstring string, const jchar *carray);
The semantics of these two functions are similar to the existing Get/ReleaseStringChars functions. If possible, the VM returns a pointer to string elements; otherwise, a copy is made. However, there are significant restrictions on how these functions can be used. In a code segment enclosed by Get/ReleaseStringCritical calls, the native code must not issue arbitrary JNI calls, or cause the current thread to block.
The restrictions on Get/ReleaseStringCritical are similar to those on Get/ReleasePrimitiveArrayCritical.

댓글

이 블로그의 인기 게시물

자바 암호화 확장 (JCE) 관련 자바 1.8.0_151 이후 변경 사항

좌표 변환: 회전 이동

Apache Commons CSV