?? miscutil.java
字號:
package jxtamessenger.util;
import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.ArrayList;
public class MiscUtil {
/** 在獲取本機IP地址發生異常時返回該值 */
public static final String IPADDRESS = "0.0.0.0";
public static String getIPAddress() {
String ip = IPADDRESS;
try {
String ha = InetAddress.getLocalHost().getHostAddress();
InetAddress[] a = InetAddress.getAllByName(ha);
if (a.length == 1) {
ip = a[0].getHostAddress();
}
} catch (UnknownHostException uhe) {
}
return ip;
}
public static String getHostName() {
String name = null;
try
{
name = InetAddress.getLocalHost().getHostName();
} catch(java.net.UnknownHostException uhe) {
}
return name;
}
public static String getUserName() {
// TODO: Read user's configuration from property file, For simplicity, here use user's host name instead.
return getHostName();
}
/**
* 由于DataOutputStream.writeUTF每次最多傳輸65535字節的數據,因此大于65535字節的數據需要手工拆分
* @param str 進行拆分的字符串
* @return 字符串數組,數組中的每個元素均剛好小于65535字節(最后一個元素除外)
* @see java.io.DataOutputStream.writeUTF
*/
public static Object[] splitUTFString(String str) {
int strlen = str.length();
int utflen = 0;
int c;
int prev = 0;
ArrayList<String> list = new ArrayList<String>();
/* use charAt instead of copying String to char array */
for (int i = 0; i < strlen;) {
c = str.charAt(i);
if ((c >= 0x0001) && (c <= 0x007F)) {
utflen++;
} else if (c > 0x07FF) {
utflen += 3;
} else {
utflen += 2;
}
if(utflen > 65535) {
list.add(str.substring(prev, i));
utflen = 0;
prev = i;
} else {
i++;
}
}
list.add(str.substring(prev));
return list.toArray();
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -