android:处理压缩字符串的快速方法
我有许多压缩字符串(每个1.5M)存储在一个文件中。我需要读出它们,并对它们进行一些计算。基本上,这就是我所做的:
public static Object fetchRSFB(File inFile) {
FileInputStream fis = null;
ObjectInputStream ois = null;
GZIPInputStream gs = null;
Object result = null;
try {
fis = new FileInputStream(inFile);
gs = new GZIPInputStream(fis);
ois = new ObjectInputStream(gs);
MyBWT.rankArray = (int[]) ois.readObject();
String str= (String) ois.readObject();
//do something with the string
唯一的问题是,代码的性能一般来说相当慢,所以我在考虑 2 个选项:
使用 NIO 将压缩文件映射到内存中,并在内存压缩文件(我听说这可能可以实现,但我不知道是不是真的)
我可以不存储对象,而是存储文本的二进制压缩版本,然后读取文本,我听说它可能比 ObjectInputStream 快。
有人知道实现上述选项的方法吗?或者有更好的方法吗,非常感谢。
I have a number of compressed String(1.5M each) stored in a file. I need to read them out, and do some computation on them. Basically, here is what I did:
public static Object fetchRSFB(File inFile) {
FileInputStream fis = null;
ObjectInputStream ois = null;
GZIPInputStream gs = null;
Object result = null;
try {
fis = new FileInputStream(inFile);
gs = new GZIPInputStream(fis);
ois = new ObjectInputStream(gs);
MyBWT.rankArray = (int[]) ois.readObject();
String str= (String) ois.readObject();
//do something with the string
The only problem is, the performance of the code is quite slow in general, so I am thinking 2 options:
to use NIO to map the compressed file into memory, and do the above on the memory compressed file(I heard that this may be achievable, but I have no idea if it really is)
Instead of storing objects, I could just store binary compressed version of the text and then read the text, I heard that it may be fast then ObjectInputStream.
Anyone knows a way of achieving the above options? or is there a better way, thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能对使用
DeflatorOutputStream 和 InflatorInputStream
感兴趣,请参阅快速压缩Java?You might be interested in using
DeflatorOutputStream and InflatorInputStream
see Fast compression in Java?