private void extractMetadata(final InputStream stream, final Metadata metadata) {
        Thread t = new Thread(() -> {
            BufferedReader reader;
            reader = new BufferedReader(new InputStreamReader(stream, UTF_8));
            try {
                String line;
                while ((line = reader.readLine()) != null) {
                    boolean consumed = false;
                    for (Map.Entry<Pattern, String> entry : metadataPatterns.entrySet()) {
                        Matcher m = entry.getKey().matcher(line);
                        if (m.find()) {
                            consumed = true;
                            if (entry.getValue() != null &&
                                    !entry.getValue().equals("")) {
                                metadata.add(entry.getValue(), m.group(1));
                            } else {
                                metadata.add(m.group(1), m.group(2));
                            }
                        }
                    }
                    if (!consumed) {
                        ignoredLineConsumer.consume(line);
                    }
                }
            } catch (IOException e) {
                // Ignore
            } finally {
                IOUtils.closeQuietly(reader);
                IOUtils.closeQuietly(stream);
            }
        });
        t.start();
        try {
            t.join();
        } catch (InterruptedException ignore) {
        }
    }
Starts a thread that sends the contents of the given input stream
to the standard input stream of the given process. Potential
exceptions are ignored, and the standard input stream is closed
once fully processed. Note that the given input stream is <em>not</em>
closed by this method.

@param process process
@param stream  input stream
tika-core/src/main/java/org/apache/tika/parser/external/ExternalParser.java