I don't have much experience with JAVA mail programming and I need help with one task. I have this code (this is a part of all code where I load attachments; if you need to see whole code, I can send) and I need to write an attachment size to a new variable I searched the web and found out that size could be get from getSize() function or by counting bytes of file but I don't know how can I write this codes. Thanks in advance.
private long analyzeAttachment(Metadata metadata, ContentHandler content, DataPipe data, long messageId) throws IOException, MessagingException{
long attid = IdGenerator.getUniqueID();
Logger.getLogger(ImapMailAnalyzer.class.getName()).log(Level.FINE, "Analyzed attachemnt {0} of message {1}", new Object[]{attid, messageId});
String attName = getAttachmentName(metadata);
data.writeRow(attid, "Abrakadabra", attName, messageId);
writeContent(attid, content, data);
return attid;
}
private String getAttachmentName(Metadata metadata){
if(metadata.get("resourceName") != null){
try {
return MimeUtility.decodeText(metadata.get("resourceName"));
} catch (UnsupportedEncodingException ex) {
Logger.getLogger(getClass().getName()).log(Level.SEVERE, null, ex);
return metadata.get("resourceName");
}
}
return "";
}