Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Excel file saved by javamail API not readable to apache poi API

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I receive a file on email which I read using javamail API and save it onto disk directory


MailExtractor.java

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


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 how to handle this one.
 
Sheriff
Posts: 24654
58
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And... does this always happen with Excel files sent by e-mail? Or only one particular file? Have you acquired a copy of that file via some other method and compared it to the result of saving it via JavaMail? Are you sure that the polling program waited for your file-saving code to finish before grabbing the file?
 
We're all out of roofs. But we still have tiny ads:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!