xhtml.startDocument();
final DirectoryNode root;
TikaInputStream tstream = TikaInputStream.cast(stream);
if (tstream == null) {
root = new NPOIFSFileSystem(new CloseShieldInputStream(stream)).getRoot();
} else {
final Object container = tstream.getOpenContainer();
if (container instanceof NPOIFSFileSystem) {
root = ((NPOIFSFileSystem) container).getRoot();
} else if (container instanceof DirectoryNode) {
root = (DirectoryNode) container;
} else if (tstream.hasFile()) {
root = new NPOIFSFileSystem(tstream.getFileChannel()).getRoot();
} else {
root = new NPOIFSFileSystem(new CloseShieldInputStream(tstream)).getRoot();
}
}
parse(root, context, metadata, xhtml);
xhtml.endDocument();
}