@Override
    public void digest(InputStream is, Metadata metadata, ParseContext parseContext)
            throws IOException {
        TikaInputStream tis = TikaInputStream.cast(is);
        if (tis != null && tis.hasFile()) {
            long sz = -1;
            if (tis.hasFile()) {
                sz = tis.getLength();
            }
            //if the inputstream has a file,
            //and its size is greater than its mark limit,
            //just digest the underlying file.
            if (sz > markLimit) {
                digestFile(tis.getFile(), sz, metadata);
                return;
            }
        }


        //try the usual mark/reset stuff.
        //however, if you actually hit the bound,
        //then stop and spool to file via TikaInputStream
        BoundedInputStream bis = new BoundedInputStream(markLimit, is);
        boolean finishedStream = false;
        bis.mark(markLimit + 1);
        finishedStream = digestStream(bis, metadata);
        bis.reset();
        if (finishedStream) {
            return;
        }
        //if the stream wasn't finished -- if the stream was longer than the mark limit --
        //spool to File and digest that.
        if (tis != null) {
            digestFile(tis.getFile(), -1, metadata);
        } else {
            TemporaryResources tmp = new TemporaryResources();
            try {
                TikaInputStream tmpTikaInputStream = TikaInputStream.get(is, tmp, metadata);
                digestFile(tmpTikaInputStream.getFile(), -1, metadata);
            } finally {
                try {
                    tmp.dispose();
                } catch (TikaException e) {
                    throw new IOException(e);
                }
            }
        }
    }
@param is           InputStream to digest. Best to use a TikaInputStream because
                    of potential need to spool to disk.  InputStream must
                    support mark/reset.
@param metadata     metadata in which to store the digest information
@param parseContext ParseContext -- not actually used yet, but there for future expansion
@throws IOException on IO problem or IllegalArgumentException if algorithm couldn't be found
tika-core/src/main/java/org/apache/tika/parser/digest/InputStreamDigester.java