Thanks Yury for your guidance.
I still cannot see how to solve this.
Do I need to read the InputStream and parse myself to recognize a workbook?
Feeding the DocumentInputStream to HSSFWorkBook constructor doesn't work.
---
import java.io.FileInputStream;
import org.apache.poi.poifs.eventfilesystem.POIFSReader;
import org.apache.poi.poifs.eventfilesystem.POIFSReaderEvent;
import org.apache.poi.poifs.eventfilesystem.POIFSReaderListener;
import org.apache.poi.poifs.filesystem.DocumentInputStream;
import org.apache.poi.poifs.filesystem.POIFSDocumentPath;
public class POIFSExtract {
public static void main(String[] args) throws Exception {
if (args == null || args.length < 1)
throw new Exception("\n->no input, no output<-");
final String fileName = args[0];
POIFSReader reader = new POIFSReader();
reader.registerListener(new MyPOIFSReaderListener());
reader.read(new FileInputStream(fileName));
}
static class MyPOIFSReaderListener implements POIFSReaderListener {
public void processPOIFSReaderEvent(POIFSReaderEvent event) {
String name = event.getName();
POIFSDocumentPath path = event.getPath();
System.out.println("got '" + name + "' event for path '" + path
+ "'.");
DocumentInputStream stream = event.getStream();
try {
byte[] buffer = new byte[stream.available()];
int read = stream.read(buffer, 0, stream.available());
System.out.println(" " + read + " bytes read.");
// TODO: "fetch" directory name , convert to DirectoryNode
and feed to HSSFWorkbook
// HSSFWorkbook wb = new HSSFWorkbook(stream);
// System.out.println(" success: workbook with " +
wb.getNumberOfSheets() + " sheets.");
}
catch (Exception e) {
System.out.println(" " + e.getMessage());
}
}
}
}
----
at runtime:
got 'SummaryInformation' event for path '/'.
436 bytes read.
got 'DocumentSummaryInformation' event for path '/'.
320 bytes read.
got 'WordDocument' event for path '/'.
11827 bytes read.
got '1Table' event for path '/'.
6311 bytes read.
got 'ObjInfo' event for path '/ObjectPool/_1147433807'.
4 bytes read.
got 'LinkInfo' event for path '/ObjectPool/_1147433807'.
92 bytes read.
got 'PRNTPICT' event for path '/ObjectPool/_1147433807'.
2310 bytes read.
got 'Ole' event for path '/ObjectPool/_1147433807'.
1748 bytes read.
got 'CompObj' event for path '/'.
88 bytes read.
got 'Data' event for path '/'.
4096 bytes read.
Many thanks for your time,
Axel.