Java 如果要对100k文档进行编码,则将PDF文件编码到base64需要更多时间
我正在尝试将pdf文档编码为base64,如果它的数量较少(比如2000个文档),那么它工作得很好。但是我有Java 如果要对100k文档进行编码,则将PDF文件编码到base64需要更多时间,java,base64,fileinputstream,Java,Base64,Fileinputstream,我正在尝试将pdf文档编码为base64,如果它的数量较少(比如2000个文档),那么它工作得很好。但是我有100k加上要编码的两个元素 对所有这些文件进行编码需要更多的时间。有没有更好的方法对大数据集进行编码 请找到我目前的方法 String filepath=doc.getPath().concat(doc.getFilename()); file = new File(filepath); if(file.exists() && !file.isDirecto
100k
加上要编码的两个元素
对所有这些文件进行编码需要更多的时间。有没有更好的方法对大数据集进行编码
请找到我目前的方法
String filepath=doc.getPath().concat(doc.getFilename());
file = new File(filepath);
if(file.exists() && !file.isDirectory()) {
try {
FileInputStream fileInputStreamReader = new FileInputStream(file);
byte[] bytes = new byte[(int) file.length()];
fileInputStreamReader.read(bytes);
encodedfile = new String(Base64.getEncoder().encodeToString(bytes));
fileInputStreamReader.close();
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
试试这个:
int files = Files.list(Paths.get(directory)).count();
int currentIndex = 0;
for (File file : filesInDir) {
if (fileMap.get(currentIndex).size() >= cap)
currentIndex++;
fileMap.get(currentIndex).add(file);
}
/** Its going to take a little more effort than this, but its the idea im trying to show you*/
for (Integer key : fileMap.keySet()) {
new WorkerThread(fileMap.get(key)).start();
}
public boolean areResourcesAvailable() {
return imNotThatNice();
}
/**
* Gets the resource utility instance
*
* @return the current instance of the resource utility
*/
private static OperatingSystemMXBean getInstance() {
if (ResourceUtil.instance == null) {
ResourceUtil.instance = ManagementFactory.getOperatingSystemMXBean();
}
return ResourceUtil.instance;
}
你看过这个帖子吗?