Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

从classpath中加载数据库文件 #8

Closed
sdvdxl opened this issue Jan 18, 2017 · 4 comments
Closed

从classpath中加载数据库文件 #8

sdvdxl opened this issue Jan 18, 2017 · 4 comments

Comments

@sdvdxl
Copy link

sdvdxl commented Jan 18, 2017

java 怎么从classpath加载文件,

URL dbURL = IpUtils.class.getClassLoader().getResource("data/ip2region.db");
searcher = new DbSearcher(new DbConfig(), dbURL.getFile());

这个加载不到,请问怎么解决

@lionsoul2014
Copy link
Owner

DbSearcher内部使用的是RandomeFileAccess,classpath中的输入流是不支持的。
你可以更改下DbSearcher的代码,可以支持memorySearch方式。但是基于文件的b-tree和binary查询的方式将都没法支持!

@sdvdxl
Copy link
Author

sdvdxl commented Jan 22, 2017

改变了方式,读取classpath的文件流,重新写入一个文件放到磁盘,读取这个文件的绝对路径。

@sdvdxl sdvdxl closed this as completed Jan 22, 2017
@lionsoul2014
Copy link
Owner

lionsoul2014 commented Jan 22, 2017

哈哈,这种方式也是可行的,棒棒的!

@wendal
Copy link

wendal commented Jul 23, 2017

看了一下DbSearcher中RandomeFileAccess的调用,可以抽取一个接口,支持 seed, readFull,close方法就可以了

wendal added a commit to wendal/ip2region that referenced this issue Jul 23, 2017
add: java客户端添加基于byte[]的数据库读取方式,摆脱本地文件的困扰
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants