mirror of
https://gitee.com/chinabugotech/hutool.git
synced 2025-04-19 03:01:48 +08:00
fix
This commit is contained in:
parent
d70687d20d
commit
1cc66f086e
@ -16,7 +16,7 @@ public class DataSizeUtil {
|
|||||||
* @param text 数据大小字符串,类似于:12KB, 5MB等
|
* @param text 数据大小字符串,类似于:12KB, 5MB等
|
||||||
* @return bytes大小
|
* @return bytes大小
|
||||||
*/
|
*/
|
||||||
public long parse(String text) {
|
public static long parse(String text) {
|
||||||
return DataSize.parse(text).toBytes();
|
return DataSize.parse(text).toBytes();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,5 +1,7 @@
|
|||||||
package cn.hutool.core.io.unit;
|
package cn.hutool.core.io.unit;
|
||||||
|
|
||||||
|
import cn.hutool.core.util.StrUtil;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 数据单位封装<p>
|
* 数据单位封装<p>
|
||||||
* 此类来自于:Spring-framework
|
* 此类来自于:Spring-framework
|
||||||
@ -69,7 +71,8 @@ public enum DataUnit {
|
|||||||
*/
|
*/
|
||||||
public static DataUnit fromSuffix(String suffix) {
|
public static DataUnit fromSuffix(String suffix) {
|
||||||
for (DataUnit candidate : values()) {
|
for (DataUnit candidate : values()) {
|
||||||
if (candidate.suffix.equalsIgnoreCase(suffix)) {
|
// 支持类似于 3MB,3M,3m等写法
|
||||||
|
if (StrUtil.startWithIgnoreCase(candidate.suffix, suffix)) {
|
||||||
return candidate;
|
return candidate;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,22 @@
|
|||||||
|
package cn.hutool.core.io.unit;
|
||||||
|
|
||||||
|
import org.junit.Assert;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class DataSizeUtilTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void parseTest(){
|
||||||
|
long parse = DataSizeUtil.parse("3M");
|
||||||
|
Assert.assertEquals(3145728, parse);
|
||||||
|
|
||||||
|
parse = DataSizeUtil.parse("3m");
|
||||||
|
Assert.assertEquals(3145728, parse);
|
||||||
|
|
||||||
|
parse = DataSizeUtil.parse("3MB");
|
||||||
|
Assert.assertEquals(3145728, parse);
|
||||||
|
|
||||||
|
parse = DataSizeUtil.parse("3mb");
|
||||||
|
Assert.assertEquals(3145728, parse);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user