diff --git a/binding/java/src/main/java/org/lionsoul/ip2region/service/Config.java b/binding/java/src/main/java/org/lionsoul/ip2region/service/Config.java index c6f1832..0cb938c 100644 --- a/binding/java/src/main/java/org/lionsoul/ip2region/service/Config.java +++ b/binding/java/src/main/java/org/lionsoul/ip2region/service/Config.java @@ -23,7 +23,7 @@ public class Config { public static final int VIndexCache = 1; public static final int BufferCache = 2; - // alias of BufferCache but easier to understand + // alias of BufferCache but easier to understand or Remember public static final int FullCache = 2; // search cache policy diff --git a/binding/java/src/test/java/org/lionsoul/ip2region/service/ConfigTest.java b/binding/java/src/test/java/org/lionsoul/ip2region/service/ConfigTest.java index c716139..ef26581 100644 --- a/binding/java/src/test/java/org/lionsoul/ip2region/service/ConfigTest.java +++ b/binding/java/src/test/java/org/lionsoul/ip2region/service/ConfigTest.java @@ -1,4 +1,6 @@ package org.lionsoul.ip2region.service; +import java.io.File; +import java.io.FileInputStream; import java.io.IOException; import java.security.CodeSource; @@ -23,13 +25,35 @@ public class ConfigTest { @Test public void testBuildV4Config() throws IOException, XdbException, InvalidConfigException { final Config v4Config = Config.custom() - .setCachePolicy(Config.BufferCache) + .setCachePolicy(Config.VIndexCache) .setXdbPath(getDataPath("ip2region_v4.xdb")) .setSearchers(20) .asV4(); log.debugf("builded config: %s", v4Config); } + @Test + public void testBuildV4ConfigFromFile() throws IOException, XdbException, InvalidConfigException { + final Config v4Config = Config.custom() + .setCachePolicy(Config.BufferCache) + .setXdbFile(new File(getDataPath("ip2region_v4.xdb"))) + .setSearchers(20) + .asV4(); + log.debugf("builded config: %s", v4Config); + } + + @Test + public void testBuildV4ConfigFromInputStream() throws IOException, XdbException, InvalidConfigException { + final Config v4Config = Config.custom() + .setCachePolicy(Config.BufferCache) + .setXdbInputStream(new FileInputStream(getDataPath("ip2region_v4.xdb"))) + .setSearchers(20) + .asV4(); + log.debugf("builded config: %s", v4Config); + } + + // --- IPv6 + @Test public void testBuildV6Config() throws IOException, XdbException, InvalidConfigException { final Config v4Config = Config.custom() @@ -39,4 +63,25 @@ public class ConfigTest { .asV6(); log.debugf("builded config: %s", v4Config); } + + @Test + public void testBuildV6ConfigFromFile() throws IOException, XdbException, InvalidConfigException { + final Config v4Config = Config.custom() + .setCachePolicy(Config.BufferCache) + .setXdbFile(new File(getDataPath("ip2region_v6.xdb"))) + .setSearchers(20) + .asV6(); + log.debugf("builded config: %s", v4Config); + } + + @Test + public void testBuildV6ConfigFromInputStream() throws IOException, XdbException, InvalidConfigException { + final Config v4Config = Config.custom() + .setCachePolicy(Config.BufferCache) + .setXdbInputStream(new FileInputStream(getDataPath("ip2region_v6.xdb"))) + .setSearchers(20) + .asV6(); + log.debugf("builded config: %s", v4Config); + } + }