public static POIFile[] readPOIFiles(final File poiFs,
final String[] poiFiles)
throws FileNotFoundException, IOException
{
final List files = new ArrayList();
POIFSReader r = new POIFSReader();
POIFSReaderListener pfl = new POIFSReaderListener()
{
public void processPOIFSReaderEvent(final POIFSReaderEvent event)
{
try
{
final POIFile f = new POIFile();
f.setName(event.getName());
f.setPath(event.getPath());
final InputStream in = event.getStream();
final ByteArrayOutputStream out =
new ByteArrayOutputStream();
Util.copy(in, out);
out.close();
f.setBytes(out.toByteArray());
files.add(f);
}
catch (IOException ex)
{
ex.printStackTrace();
throw new RuntimeException(ex.getMessage());
}
}
};
if (poiFiles == null)
/* Register the listener for all POI files. */
r.registerListener(pfl);
else
/* Register the listener for the specified POI files
* only. */
for (int i = 0; i < poiFiles.length; i++)
r.registerListener(pfl, poiFiles[i]);
/* Read the POI filesystem. */
r.read(new FileInputStream(poiFs));
POIFile[] result = new POIFile[files.size()];
for (int i = 0; i < result.length; i++)
result[i] = (POIFile) files.get(i);
return result;
}