BufferedInputStream bis = null;
StringBuilder buffy = new StringBuilder();
try {
bis = new BufferedInputStream(leaf.getInputStream());
POIXMLTextExtractor extractor = (POIXMLTextExtractor) ExtractorFactory.createExtractor(bis);
POIXMLDocument document = extractor.getDocument();
if (document instanceof XWPFDocument) {
XWPFDocument xDocument = (XWPFDocument) document;
XWPFHeaderFooterPolicy hfPolicy = xDocument.getHeaderFooterPolicy();
extractHeaders(buffy, hfPolicy);