punycode java_Java StringUtils.strip方法代碼示例

import org.apache.commons.lang3.StringUtils; //導入方法依賴的package包/類

/**

* @return IDN normalized hostname

*/

public String convert(final String hostname) {

if(!PreferencesFactory.get().getBoolean("connection.hostname.idn")) {

return StringUtils.strip(hostname);

}

if(StringUtils.isNotEmpty(hostname)) {

try {

// Convenience function that implements the IDNToASCII operation as defined in

// the IDNA RFC. This operation is done on complete domain names, e.g: "www.example.com".

// It is important to note that this operation can fail. If it fails, then the input

// domain name cannot be used as an Internationalized Domain Name and the application

// should have methods defined to deal with the failure.

// IDNA.DEFAULT Use default options, i.e., do not process unassigned code points

// and do not use STD3 ASCII rules If unassigned code points are found

// the operation fails with ParseException

final String idn = IDN.toASCII(StringUtils.strip(hostname));

if(log.isDebugEnabled()) {

if(!StringUtils.equals(StringUtils.strip(hostname), idn)) {

log.debug(String.format("IDN hostname for %s is %s", hostname, idn));

}

}

if(StringUtils.isNotEmpty(idn)) {

return idn;

}

}

catch(IllegalArgumentException e) {

log.warn(String.format("Failed to convert hostname %s to IDNA", hostname), e);

}

}

return StringUtils.strip(hostname);

}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值