chinese characters can be handled correctly.
This commit is contained in:
parent
bbbf500be8
commit
3d296d0ef1
|
@ -1,17 +1,26 @@
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
char * GetJString(JNIEnv * environment, jstring jstr)
|
char * GetJString(JNIEnv * environment, jstring str)
|
||||||
{
|
{
|
||||||
jsize length = environment->GetStringLength(jstr);
|
jsize length=environment->GetStringLength(str);
|
||||||
const jchar * jcstr = environment->GetStringChars( jstr, NULL );
|
const jchar * jcstr=environment->GetStringChars(str,NULL);
|
||||||
int size=0;
|
int size=0;
|
||||||
char *str=(char *)malloc(length*2+1);
|
char * ret=(char *)malloc(length*2+1);
|
||||||
if((size=WideCharToMultiByte(CP_ACP,0,LPCWSTR(jcstr),length,str,length*2+1,NULL,NULL))==0)
|
if((size=WideCharToMultiByte(CP_ACP,0,LPCWSTR(jcstr),length,ret,length*2+1,NULL,NULL))==0)
|
||||||
{
|
{
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
environment->ReleaseStringChars(jstr,jcstr);
|
environment->ReleaseStringChars(str,jcstr);
|
||||||
str[size] = 0;
|
ret[size]='\0';
|
||||||
return str;
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
char * GetUTF8String(const wchar_t * str)
|
||||||
|
{
|
||||||
|
int length=WideCharToMultiByte(CP_UTF8,NULL,str,(long)wcslen(str),NULL,0,NULL,NULL);
|
||||||
|
char * ret=new char[length + 1];
|
||||||
|
WideCharToMultiByte(CP_UTF8,NULL,str,(long)wcslen(str),ret,length,NULL,NULL);
|
||||||
|
ret[length]='\0';
|
||||||
|
return ret;
|
||||||
}
|
}
|
|
@ -3,3 +3,4 @@
|
||||||
#include <jni.h>
|
#include <jni.h>
|
||||||
|
|
||||||
char * GetJString(JNIEnv * environment, jstring jstr);
|
char * GetJString(JNIEnv * environment, jstring jstr);
|
||||||
|
char * GetUTF8String(const wchar_t * str);
|
|
@ -14,7 +14,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_bench4q_monitor_performance_windows_Logi
|
||||||
for(iter=instances.begin();iter!=instances.end();iter++)
|
for(iter=instances.begin();iter!=instances.end();iter++)
|
||||||
{
|
{
|
||||||
environment->SetObjectArrayElement(array,i
|
environment->SetObjectArrayElement(array,i
|
||||||
,environment->NewStringUTF(Common::WideStringToString(*iter).c_str()));
|
,environment->NewStringUTF(GetUTF8String((*iter).c_str())));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
|
@ -32,7 +32,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_bench4q_monitor_performance_windows_Logi
|
||||||
for(iter=counterList.begin();iter!=counterList.end();iter++)
|
for(iter=counterList.begin();iter!=counterList.end();iter++)
|
||||||
{
|
{
|
||||||
environment->SetObjectArrayElement(array,i
|
environment->SetObjectArrayElement(array,i
|
||||||
,environment->NewStringUTF(Common::WideStringToString(*iter).c_str()));
|
,environment->NewStringUTF(GetUTF8String((*iter).c_str())));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include "stdafx.h"
|
#include "stdafx.h"
|
||||||
#include "MemoryMonitor.h"
|
#include "MemoryMonitor.h"
|
||||||
|
#include "Common.h"
|
||||||
|
|
||||||
JNIEXPORT jobjectArray JNICALL Java_org_bench4q_monitor_performance_windows_MemoryMonitor_getCounterList
|
JNIEXPORT jobjectArray JNICALL Java_org_bench4q_monitor_performance_windows_MemoryMonitor_getCounterList
|
||||||
(JNIEnv * environment, jobject object)
|
(JNIEnv * environment, jobject object)
|
||||||
|
@ -13,7 +14,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_bench4q_monitor_performance_windows_Memo
|
||||||
for(iter=counterList.begin();iter!=counterList.end();iter++)
|
for(iter=counterList.begin();iter!=counterList.end();iter++)
|
||||||
{
|
{
|
||||||
environment->SetObjectArrayElement(array,i
|
environment->SetObjectArrayElement(array,i
|
||||||
,environment->NewStringUTF(Common::WideStringToString(*iter).c_str()));
|
,environment->NewStringUTF(GetUTF8String((*iter).c_str())));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
|
|
|
@ -14,7 +14,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_bench4q_monitor_performance_windows_Netw
|
||||||
for(iter=instances.begin();iter!=instances.end();iter++)
|
for(iter=instances.begin();iter!=instances.end();iter++)
|
||||||
{
|
{
|
||||||
environment->SetObjectArrayElement(array,i
|
environment->SetObjectArrayElement(array,i
|
||||||
,environment->NewStringUTF(Common::WideStringToString(*iter).c_str()));
|
,environment->NewStringUTF(GetUTF8String((*iter).c_str())));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
|
@ -32,7 +32,7 @@ JNIEXPORT jobjectArray JNICALL Java_org_bench4q_monitor_performance_windows_Netw
|
||||||
for(iter=counterList.begin();iter!=counterList.end();iter++)
|
for(iter=counterList.begin();iter!=counterList.end();iter++)
|
||||||
{
|
{
|
||||||
environment->SetObjectArrayElement(array,i
|
environment->SetObjectArrayElement(array,i
|
||||||
,environment->NewStringUTF(Common::WideStringToString(*iter).c_str()));
|
,environment->NewStringUTF(GetUTF8String((*iter).c_str())));
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
return array;
|
return array;
|
||||||
|
|
|
@ -76,7 +76,7 @@ public class Main {
|
||||||
for (String elem : networkInterfaceInstances) {
|
for (String elem : networkInterfaceInstances) {
|
||||||
System.out.println(elem);
|
System.out.println(elem);
|
||||||
System.out.println("bandwidth:"
|
System.out.println("bandwidth:"
|
||||||
+ networkInterfaceMonitor.getCurrentBandwidth("Broadcom 802.11n 网络适配器"));
|
+ networkInterfaceMonitor.getCurrentBandwidth(elem));
|
||||||
}
|
}
|
||||||
|
|
||||||
// String[] networkInterfaceCounter = networkInterfaceMonitor
|
// String[] networkInterfaceCounter = networkInterfaceMonitor
|
||||||
|
|
Loading…
Reference in New Issue