在 imap 上,我试图从多条消息中获取附件。它工作正常,但如果有一个大约 20 兆字节的附件,那么它似乎卡住了,java 没有继续。
这就是问题发生的地方:我想获取附件的内容并将其保存到字符串中:
...
MimeBodyPart attachment = (MimeBodyPart) multipart.getBodyPart(1);
if(!Part.ATTACHMENT.equalsIgnoreCase(attachment.getDisposition())) {
log.error("Part is not an attachment!");
} else {
log.debug("Checking " + localFile.getName() + " with " + attachment.getFileName() + ". Attachment-Size: " + (attachment.getSize()/(1024*1024)) + " mega-bytes.");
InputStream remoteFileIs = attachment.getInputStream();
remoteFileContent = IOUtils.toString(remoteFileIs); //stucked here, when attachment is large
remoteFileIs.close();
...
}
...
有什么解决办法吗?
问候!