我试图验证附件是否受密码保护,是否有可以检查的属性。如果附件受密码保护,我不想处理附件。
以下是我尝试的代码:
FileAttachment fileAttachment = (FileAttachment) attachment;
// if we don't call this, the Content property may be null.
fileAttachment.load();
// I was hoping this should not give me content of the file if it's password protected
attachmentContent = fileAttachment.getContent(); //but I get the content without error.
if (attachmentContent != null && attachmentContent.length > 0) {
//check the size, I get the length as well
int attachmentSize = attachmentContent.length;
我再次检查是否可以解码内容,我也可以获得解码内容。
byte[] decodedFile;
try {
String base64Encoded = Base64.encodeBase64String(attachmentContent);
decodedFile = Base64.decodeBase64(base64Encoded);
} catch (Exception e) {
throw e);
}