Hi,
 I am trying to use the following code sample to know whether a document
is empty or not:
==========================================================
import org.apache.poi.hpsf.*;
import org.apache.poi.poifs.eventfilesystem.*;
import org.apache.poi.util.HexDump;
 
public class POIFSTest 
{
 public static void readAdvanceSummary(String docPath)
 {
     final String filename = "C:\\temp\\WDoc001.doc";
     POIFSReader r = new POIFSReader();
     r.registerListener(new MyPOIFSReaderListener(),
"\005SummaryInformation");
    
     try {
      r.read(new FileInputStream(filename));
     }
     catch(Exception e) {
     }
 }
 
 static class MyPOIFSReaderListener implements POIFSReaderListener
 {
     public void processPOIFSReaderEvent(POIFSReaderEvent event)
     {
         // get the property stream (different for various versions of
ms word document) - starts here
         SummaryInformation si = null;
         try
         {
             si = (SummaryInformation)
                  PropertySetFactory.create(event.getStream());
          charCount = si.getCharCount();
         }
         catch (Exception ex)
         {}
     }
 }
}
==========================================================
Some of the documents while reading throws the following exception:
 
java.io.IOException: Unable to read entire block; 10 bytes read;
expected 512 bytes
 at
org.apache.poi.poifs.storage.RawDataBlock.<init>(RawDataBlock.java:62)
 at
org.apache.poi.poifs.storage.RawDataBlockList.<init>(RawDataBlockList.ja
va:51)
 at
org.apache.poi.poifs.eventfilesystem.POIFSReader.read(POIFSReader.java:1
4)
 at src.com.mitchell.POIFSTest.readAdvanceSummary(POIFSTest.java:7)

java.io.IOException: Unable to read entire block; 491 bytes read;
expected 512 bytes
 at
org.apache.poi.poifs.storage.RawDataBlock.<init>(RawDataBlock.java:62)
 at
org.apache.poi.poifs.storage.RawDataBlockList.<init>(RawDataBlockList.ja
va:51)
 at
org.apache.poi.poifs.eventfilesystem.POIFSReader.read(POIFSReader.java:1
4)
 at src.com.mitchell.POIFSTest.readAdvanceSummary(POIFSTest.java:7)
 
These exceptions are because the documents are empty.
Any suggestion will be highly appreciated.
 
Thanks,
Vinay

Reply via email to