MailExtractor.java
* Multipart multiPart = (Multipart) message.getContent();
int numberOfParts = multiPart.getCount();
for (int partCount = 0; partCount < numberOfParts; partCount++) {
MimeBodyPart part = (MimeBodyPart) multiPart.getBodyPart(partCount);
if (Part.ATTACHMENT.equalsIgnoreCase(part.getDisposition())) {
// this part is attachment
String fileName = part.getFileName();
attachFiles += fileName + ", ";
part.saveFile(saveDir + File.separator + fileName);
}
else {
// this part may be the message content
messageContent = part.getContent().toString();
}
}*
Now another program polls that disk directory and reads all incoming file. I
am only concerned with File extensions - xls/xlsx, so I use apache poi to
read the files:
*//AvailabilityDirectoryPoller.java
FileInputStream fs = new FileInputStream(file);
Workbook wb = null;
Sheet sheet = null;
if(FilenameUtils.getExtension(file.getName()).equalsIgnoreCase("xls")){
wb = new HSSFWorkbook(fs); //line no 178
sheet = (HSSFSheet)wb.getSheetAt(0);
}
else{
wb = new XSSFWorkbook(fs);
sheet = (XSSFSheet)wb.getSheetAt(0);
} *
This sometimes(read random) results in error as below
[2013-07-18 23:38:32,409] ERROR [AvailabilityDirectoryPoller]: Exception in
I/O Reading file
java.io.IOException: Your file contains 79 sectors, but the initial DIFAT
array at index 1 referenced block # 98. This isn't allowed and your file is
corrupt
at
org.apache.poi.poifs.storage.BlockAllocationTableReader.<init>(BlockAllocationTableReader.java:103)
at
org.apache.poi.poifs.filesystem.POIFSFileSystem.<init>(POIFSFileSystem.java:151)
at
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:322)
at
org.apache.poi.hssf.usermodel.HSSFWorkbook.<init>(HSSFWorkbook.java:303)
at
com.db.mmrepo.app.avl.bespoke.AvailabilityDirectoryPoller.process(AvailabilityDirectoryPoller.java:178)
at
com.db.mmrepo.app.avl.bespoke.AvailabilityDirectoryPoller.fileFound(AvailabilityDirectoryPoller.java:73)
at
org.sadun.util.polling.DefaultListener.receive(DefaultListener.java:43)
at com.deltax.util.listener.SignalQueue.run(Unknown Source)
If I open the javamail saved file in MS Excel, it opens with no
warnings/errors.
Please advice.
--
View this message in context:
http://apache-poi.1045710.n5.nabble.com/Excel-file-saved-by-javamail-API-not-readable-to-apache-poi-API-tp5713266.html
Sent from the POI - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]