This commit is contained in:
Looly
2021-03-12 22:30:52 +08:00
parent eb1ca9b679
commit d9ce2aff95
5 changed files with 26 additions and 4 deletions

View File

@@ -47,7 +47,7 @@ public abstract class CRC16Checksum implements Checksum, Serializable {
public String getHexValue(boolean isPadding){
String hex = HexUtil.toHex(getValue());
if(isPadding){
hex = StrUtil.padAfter(hex, 4, '0');
hex = StrUtil.padPre(hex, 4, '0');
}
return hex;

View File

@@ -222,7 +222,7 @@ public class UrlQuery {
sb.append("&");
}
key = entry.getKey();
if (StrUtil.isNotEmpty(key)) {
if (null != key) {
sb.append(URLUtil.encodeAll(StrUtil.str(key), charset));
value = entry.getValue();
if (null != value) {

View File

@@ -1,12 +1,14 @@
package cn.hutool.core.io.checksum;
import cn.hutool.core.io.checksum.crc16.CRC16XModem;
import cn.hutool.core.util.HexUtil;
import cn.hutool.core.util.StrUtil;
import org.junit.Assert;
import org.junit.Test;
/**
* CRC校验单元测试
*
*
* @author looly
*
*/
@@ -40,4 +42,14 @@ public class CrcTest {
String crc16 = HexUtil.toHex(crc.getValue());
Assert.assertEquals("18c", crc16);
}
@Test
public void paddingTest(){
// I3B3RV@Gitee
String text = "000123FFFFFF";
CRC16XModem crc16 = new CRC16XModem();
crc16.update(StrUtil.bytes(text));
String hexValue = crc16.getHexValue(true);
Assert.assertEquals("0e04", hexValue);
}
}

View File

@@ -26,4 +26,12 @@ public class UrlQueryTest {
final String queryStr = urlBuilder.getQueryStr();
Assert.assertEquals("imageMogr2/auto-orient/thumbnail/500&pid=259848", queryStr);
}
@Test
public void parseTest2(){
String requestUrl = "http://192.168.1.1:8080/pc?=d52i5837i4ed=o39-ap9e19s5--=72e54*ll0lodl-f338868d2";
UrlQuery q = new UrlQuery();
UrlQuery parse = q.parse(requestUrl, Charset.defaultCharset());
Assert.assertEquals("=d52i5837i4ed=o39-ap9e19s5--=72e54*ll0lodl-f338868d2", parse.toString());
}
}