jobject CRJNIEnv::toJavaProperties( CRPropRef props ) { jclass cls = env->FindClass("java/util/Properties"); jmethodID mid = env->GetMethodID(cls, "<init>", "()V"); jobject obj = env->NewObject(cls, mid); CRObjectAccessor jp(env, obj); CRMethodAccessor p_setProperty(jp, "setProperty", "(Ljava/lang/String;Ljava/lang/String;)Ljava/lang/Object;"); for ( int i=0; i<props->getCount(); i++ ) { jstring key = toJavaString(lString16(props->getName(i))); jstring value = toJavaString(lString16(props->getValue(i))); p_setProperty.callObj(key, value); env->DeleteLocalRef(key); env->DeleteLocalRef(value); } return obj; }
/** * Returns the content type corresponding to the supplied file extension. * The mapping is determined using Uniform Type Identifiers (UTIs). If * the file extension parameter is NULL, a CFString cannot be created * from the file extension parameter, there is no UTI corresponding to * the file extension, the UTI cannot supply a MIME type for the file * extension, or a Java string cannot be created, then NULL is returned; * otherwise the MIME type string is returned. */ JNIEXPORT jstring JNICALL Java_sun_nio_fs_UTIFileTypeDetector_probe0(JNIEnv* env, jobject ftd, jstring ext) { jstring result = NULL; CFStringRef extension = toCFString(env, ext); if (extension != NULL) { CFStringRef uti = UTTypeCreatePreferredIdentifierForTag(kUTTagClassFilenameExtension, extension, NULL); CFRelease(extension); if (uti != NULL) { CFStringRef mimeType = UTTypeCopyPreferredTagWithClass(uti, kUTTagClassMIMEType); CFRelease(uti); if (mimeType != NULL) { result = toJavaString(env, mimeType); CFRelease(mimeType); } } } return result; }
jobjectArray CRJNIEnv::toJavaStringArray( lString16Collection & src ) { int len = src.length(); jobjectArray array = env->NewObjectArray(len, env->FindClass("java/lang/String"), env->NewStringUTF("")); for ( int i=0; i<len; i++ ) { jstring local = toJavaString(src[i]); env->SetObjectArrayElement(array, i, local); env->DeleteLocalRef(local); } return array; }