@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 testParseGlobalMetadataMultiLineMetadataValues() throws Exception {
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        IOUtils.copy(EnviHeaderParserTest.class.getResourceAsStream("/ground-truth" +
                "/EnviHeaderGroundTruth.txt"), bos);
        String expected = new String(bos.toByteArray(), StandardCharsets.UTF_8).trim();
        Parser parser = new EnviHeaderParser();
        ToXMLContentHandler handler = new ToXMLContentHandler();
        Metadata metadata = new Metadata();

        try (InputStream stream = EnviHeaderParser.class
                .getResourceAsStream("/test-documents/ang20150420t182050_corr_v1e_img.hdr")) {
            assertNotNull(stream, "Test ENVI file 'ang20150420t182050_corr_v1e_img.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>description = {  Georeferenced Image built from input GLT. " +
                        "[Wed Jun 10 04:37:54 2015] [Wed  Jun 10 04:48:52 2015]}</p>",
                content);
        assertContains("<p>samples = 739</p>", content);
        assertContains("<p>lat/lon = { 36.79077627261556, -108.48370867914815 }</p>", content);
        assertContains(
                "<p>map info = { UTM , 1.000 , 1.000 , 724522.127 , 4074620.759 , " +
                        "1.1000000000e+00 , 1.1000000000e+00 , 12 , North , " +
                        "WGS-84 , units=Meters , " +
                        "rotation=75.00000000 }</p>",
                content);
        assertContains( expected,
                content);
    }