public static TikaInputStream get(Blob blob, Metadata metadata) throws SQLException {

        long length = -1;
        try {
            length = blob.length();
            metadata.set(Metadata.CONTENT_LENGTH, Long.toString(length));
        } catch (SQLException ignore) {
        }

        // Prefer an in-memory buffer for reasonably sized blobs to reduce
        // the likelihood of problems caused by long-lived database accesses
        if (0 <= length && length <= BLOB_SIZE_THRESHOLD) {
            // the offset in Blob.getBytes() starts at 1
            return get(blob.getBytes(1, (int) length), metadata);
        } else {
            return new TikaInputStream(new BufferedInputStream(blob.getBinaryStream()),
                    new TemporaryResources(), length,
                    getExtension(metadata));
        }
    }
Creates a TikaInputStream from the given database BLOB. The BLOB
length (if available) is stored as input metadata in the given
metadata instance.
<p>
Note that the result set containing the BLOB may need to be kept open
until the returned TikaInputStream has been processed and closed.
You must also always explicitly close the returned stream as in
some cases it may end up writing the blob data to a temporary file.

@param blob     database BLOB
@param metadata metadata instance
@return a TikaInputStream instance
@throws SQLException if BLOB data can not be accessed
tika-core/src/main/java/org/apache/tika/io/TikaInputStream.java