mirror of
https://gitee.com/matrixy/dns-cheater.git
synced 2026-05-06 16:50:17 +08:00
@@ -1,6 +1,7 @@
|
||||
package cn.org.hentai.dns.stat;
|
||||
|
||||
import cn.org.hentai.dns.util.Configs;
|
||||
import cn.org.hentai.dns.util.Conversion;
|
||||
import cn.org.hentai.dns.util.Packet;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -33,7 +34,9 @@ public final class StatManager
|
||||
|
||||
private StatManager()
|
||||
{
|
||||
logs = Packet.create(1024 * 1024 * 200);
|
||||
String lmem = Configs.get("dns.stat-logger.memory");
|
||||
int i = Conversion.toByte(lmem);
|
||||
logs = Packet.create(i);
|
||||
domainNameMap = new HashMap();
|
||||
sequence = 1;
|
||||
|
||||
|
||||
35
src/main/java/cn/org/hentai/dns/util/Conversion.java
Normal file
35
src/main/java/cn/org/hentai/dns/util/Conversion.java
Normal file
@@ -0,0 +1,35 @@
|
||||
package cn.org.hentai.dns.util;
|
||||
|
||||
/**
|
||||
* Created by huangzhian on 2019/10/21.
|
||||
*/
|
||||
public class Conversion {
|
||||
|
||||
/**
|
||||
* 将配置的缓存空间单位KMG转换为byte,
|
||||
* 因为int类型的限制,将最大缓存空间设为1G
|
||||
*/
|
||||
public static int toByte(String memory) {
|
||||
int count = 0;
|
||||
String mem;
|
||||
if (memory == null) {
|
||||
return 0;
|
||||
}
|
||||
mem = memory.toUpperCase();
|
||||
if (mem.matches("[0-9]+[KMG]{1}")) {
|
||||
String submem = memory.substring(0, memory.length() - 1);
|
||||
count = Integer.parseInt(submem);
|
||||
} else if (mem.matches("[0-9]+")) {
|
||||
count = Integer.parseInt(memory);
|
||||
}
|
||||
if (mem.endsWith("M")) {
|
||||
return (count > 1024 ? 1024 : count) << 20;
|
||||
} else if (mem.endsWith("G")) {
|
||||
return (count > 1 ? 1 : count) << 30;
|
||||
} else if (mem.endsWith("K")) {
|
||||
return count << 10;
|
||||
} else {
|
||||
return count;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user