public static OpcPackage load(final InputStream inputStream, String password) throws Docx4JException { //try to detect the type of file using a bufferedinputstream final BufferedInputStream bis = new BufferedInputStream(inputStream); bis.mark(0); final byte[] firstTwobytes=new byte[2]; int read=0; try { read = bis.read(firstTwobytes); bis.reset(); } catch (final IOException e) { throw new Docx4JException("Error reading from the stream", e); } if (read!=2){ throw new Docx4JException("Error reading from the stream (no bytes available)"); } if (firstTwobytes[0]=='P' && firstTwobytes[1]=='K') { // 50 4B return OpcPackage.load(bis, Filetype.ZippedPackage, null); } else if (firstTwobytes[0]==(byte)0xD0 && firstTwobytes[1]==(byte)0xCF) { // password protected docx is a compound file, with signature D0 CF 11 E0 A1 B1 1A E1 log.info("Detected compound file"); return OpcPackage.load(bis, Filetype.Compound, password); } else { //Assume.. log.info("Assuming Flat OPC XML"); return OpcPackage.load(bis, Filetype.FlatOPC, null); } }