public static TikaInputStream get(URL url, Metadata metadata) throws IOException {
        // Special handling for file:// URLs
        if ("file".equalsIgnoreCase(url.getProtocol())) {
            try {
                Path path = Paths.get(url.toURI());
                if (Files.isRegularFile(path)) {
                    return get(path, metadata);
                }
            } catch (URISyntaxException e) {
                // fall through
            }
        }

        URLConnection connection = url.openConnection();

        String path = url.getPath();
        int slash = path.lastIndexOf('/');
        if (slash + 1 < path.length()) { // works even with -1!
            metadata.set(TikaCoreProperties.RESOURCE_NAME_KEY, path.substring(slash + 1));
        }

        String type = connection.getContentType();
        if (type != null) {
            metadata.set(Metadata.CONTENT_TYPE, type);
        }

        String encoding = connection.getContentEncoding();
        if (encoding != null) {
            metadata.set(Metadata.CONTENT_ENCODING, encoding);
        }

        int length = connection.getContentLength();
        if (length >= 0) {
            metadata.set(Metadata.CONTENT_LENGTH, Integer.toString(length));
        }

        return new TikaInputStream(new BufferedInputStream(connection.getInputStream()),
                new TemporaryResources(), length, getExtension(metadata));
    }
Creates a TikaInputStream from the resource at the given URL. The
available input metadata is stored in the given metadata instance.
<p>
Note that you must always explicitly close the returned stream as in
some cases it may end up writing the resource to a temporary file.

@param url      resource URL
@param metadata metadata instance
@return a TikaInputStream instance
@throws IOException if the resource can not be accessed
tika-core/src/main/java/org/apache/tika/io/TikaInputStream.java