List of usage examples for org.apache.poi.poifs.filesystem DocumentFactoryHelper hasOOXMLHeader
@Deprecated @Removal(version = "4.0") public static boolean hasOOXMLHeader(InputStream inp) throws IOException
If unsure if your InputStream does support mark / reset, use FileMagic#prepareToCheckMagic(InputStream) to wrap it and make sure to always use that, and not the original!
From source file:com.netsteadfast.greenstep.util.SimpleUtils.java
License:Apache License
/** * http://stackoverflow.com/questions/12593752/why-do-i-failed-to-read-excel-2007-using-poi * /*from w w w .j av a2 s. c om*/ * @param inp * @return * @throws IOException * @throws InvalidFormatException */ public static Workbook createPOIWorkbook(InputStream inp) throws IOException, InvalidFormatException { // If clearly doesn't do mark/reset, wrap up if (!inp.markSupported()) { inp = new PushbackInputStream(inp, 8); } if (POIFSFileSystem.hasPOIFSHeader(inp)) { return new HSSFWorkbook(inp); } if (DocumentFactoryHelper.hasOOXMLHeader(inp)) { return new XSSFWorkbook(OPCPackage.open(inp)); } throw new IllegalArgumentException("Your InputStream was neither an OLE2 stream, nor an OOXML stream"); }