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);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);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, orNULL if the operation fails.void ReleaseStringChars(JNIEnv *env, jstring string, const jchar *chars);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.
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, orNULL if the string cannot be constructed.THROWS:
OutOfMemoryError: if the system runs out of memory.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.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.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.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.
댓글
댓글 쓰기