@Override
    public void parse(InputStream stream, ContentHandler handler, Metadata metadata,
                      ParseContext context) throws IOException, SAXException, TikaException {

        // Only outputting the MIME type as metadata
        metadata.set(Metadata.CONTENT_TYPE, ENVI_MIME_TYPE);

        // The following code was taken from the TXTParser
        // Automatically detect the character encoding
        try (AutoDetectReader reader = new AutoDetectReader(CloseShieldInputStream.wrap(stream),
                metadata, getEncodingDetector(context))) {
            Charset charset = reader.getCharset();
            // deprecated, see TIKA-431
            metadata.set(Metadata.CONTENT_ENCODING, charset.name());
            xhtml = new XHTMLContentHandler(handler, metadata);
            xhtml.startDocument();
            readLines(reader, metadata);
            xhtml.endDocument();
        } catch (IOException | TikaException e) {
            LOG.error("Error reading input data stream.", e);
        }

    }
@Test
    public void testParseGlobalMetadata() throws Exception {

        try (InputStream stream = EnviHeaderParser.class
                .getResourceAsStream("/test-documents/envi_test_header.hdr")) {
            assertNotNull(stream, "Test ENVI file 'envi_test_header.hdr' not found");
            parser.parse(stream, handler, metadata, new ParseContext());
        }

        // Check content of test file
        String content = handler.toString();
        assertContains("<body><p>ENVI</p>", content);
        assertContains("<p>samples = 2400</p>", content);
        assertContains("<p>lines   = 2400</p>", content);
        assertContains(
                "<p>map info = {Sinusoidal, 1.5000, 1.5000, -10007091.3643, " +
                        "5559289.2856, 4.6331271653e+02, 4.6331271653e+02, , units=Meters}</p>",
                content);
        assertContains("content=\"application/envi.hdr\"", content);
        assertContains(
                "projection info = {16, 6371007.2, 0.000000, 0.0, 0.0, Sinusoidal, units=Meters}",
                content);
    }