Example usage for org.apache.poi.poifs.common POIFSConstants OOXML_FILE_HEADER

List of usage examples for org.apache.poi.poifs.common POIFSConstants OOXML_FILE_HEADER

Introduction

In this page you can find the example usage for org.apache.poi.poifs.common POIFSConstants OOXML_FILE_HEADER.

Prototype

null OOXML_FILE_HEADER

To view the source code for org.apache.poi.poifs.common POIFSConstants OOXML_FILE_HEADER.

Click Source Link

Document

The first 4 bytes of an OOXML file, used in detection

Usage

From source file:org.alfresco.repo.content.TikaOfficeDetectParser.java

License:Open Source License

public void parse(InputStream stream, ContentHandler handler, Metadata metadata, ParseContext parseContext)
        throws IOException, SAXException, TikaException {
    byte[] initial4 = new byte[4];
    InputStream wrapped;//from  w w w .j  a  v a  2s.com
    // Preserve TikaInputStreams as TikaInputStreams as they require less memory to process
    if (stream.markSupported()) {
        stream.mark(initial4.length);
        IOUtils.readFully(stream, initial4);
        stream.reset();
        wrapped = stream;
    } else {
        PushbackInputStream inp = new PushbackInputStream(stream, 4);
        IOUtils.readFully(inp, initial4);
        inp.unread(initial4);
        wrapped = inp;
    }

    // Which is it?
    if (initial4[0] == POIFSConstants.OOXML_FILE_HEADER[0] && initial4[1] == POIFSConstants.OOXML_FILE_HEADER[1]
            && initial4[2] == POIFSConstants.OOXML_FILE_HEADER[2]
            && initial4[3] == POIFSConstants.OOXML_FILE_HEADER[3]) {
        ooxmlParser.parse(wrapped, handler, metadata, parseContext);
    } else {
        ole2Parser.parse(wrapped, handler, metadata, parseContext);
    }
}

From source file:org.dhatim.fastexcel.reader.ReadableWorkbook.java

License:Apache License

public static boolean isOOXMLZipHeader(byte[] bytes) {
    requireLength(bytes, POIFSConstants.OOXML_FILE_HEADER.length);
    return arrayEquals(bytes, 0, POIFSConstants.OOXML_FILE_HEADER, 0, POIFSConstants.OOXML_FILE_HEADER.length);
}