【发布时间】:2014-08-14 16:29:24
【问题描述】:
我使用 pdf 库将 PDF 转换为图像。这个过程需要很多时间,我用了profiler 来查找问题的原因,这一切都归结为一种方法(>60% CPU 时间)。现在我的问题是:
这种方法可以进一步改进吗?
public int read(byte[] b) throws IOException {
if (buf==null) throw new IOException("Data buffer not initialized.");
if (pointer<0 || pointer>=length)
return -1;
int length=this.length-(int)pointer;
if(length>b.length)
length=b.length;
for (int i=0; i<length; i++) {
buf.seek(pointer++);
b[i] = buf.readByte();
}
return length;
}
【问题讨论】:
-
为什么不简单地将pdf文件用作RandomAccessFile?我没有看到 RandomAccessMemoryMapBuffer 引入的附加层有任何优势。
-
没错!我也是这么想的——为什么不使用 RandomAccessFile。但是当您查看源代码时,这似乎是有症状的......
标签: java performance algorithm optimization profiling