On Wed, 22 Mar 2017, Thiyagarajan wrote:
I have an InputStream wrapped in a BufferedInputStream and I'm trying to
detect whether it is a normal zip file or a xlsx file (and take appropriate
actions accordingly). I have tried to use  hasOOXMLHeader
<https://github.com/apache/poi/blob/trunk/src/java/org/apache/poi/poifs/filesystem/DocumentFactoryHelper.java#L91>
to achieve this. But it just checks if the input stream is a zip file and
there is nothing specific for an xlsx file there. (I understand that xlsx is
a zip file with a bunch of xml files).

Is it possible to detect if the inputstream is from xlsx file or a normal
zip file?

Not easily from an InputStream. You'd need to check if there's a [Content_Types].xml file in the zip to have a good idea, and that may not be the first file in the zip. So, you'll need to buffer the zip stream into memory, and parse through the entries to see if there's a content types, and rewind back to process if so. Much easier with a File, as you can easily do random-access to check without buffering

Nick

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscr...@poi.apache.org
For additional commands, e-mail: user-h...@poi.apache.org

Reply via email to