//  [java]
    public Optional<InputStream> getResourceAsStream(String path) {
        if (missingPath) {
            return Optional.empty();
        }

        URL url = classLoader.getResource(prefixPath(path));
        if (url != null) {
            if (startsWithBase(url)) {
                try {
                    URI uri = url.toURI();
                    if (uri.getScheme().equals("jar")) {
                        synchronized (DefaultClassPathResourceLoader.class) {
                            FileSystem fileSystem = null;
                            try {
                                try {
                                    fileSystem = FileSystems.getFileSystem(uri);
                                } catch (FileSystemNotFoundException e) {
                                    //no-op
                                }
                                if (fileSystem == null || !fileSystem.isOpen()) {
                                    try {
                                        fileSystem = FileSystems.newFileSystem(uri, Collections.emptyMap(), classLoader);
                                    } catch (FileSystemAlreadyExistsException e) {
                                        fileSystem = FileSystems.getFileSystem(uri);
                                    }
                                }
                                Path pathObject = fileSystem.getPath(path);
                                if (Files.isDirectory(pathObject)) {
                                    return Optional.empty();
                                }
                                return Optional.of(new ByteArrayInputStream(Files.readAllBytes(pathObject)));
                            } finally {
                                if (fileSystem != null && fileSystem.isOpen()) {
                                    try {
                                        fileSystem.close();
                                    } catch (IOException e) {
                                        if (LOG.isDebugEnabled()) {
                                            LOG.debug("Error shutting down JAR file system [" + fileSystem + "]: " + e.getMessage(), e);
                                        }
                                    }
                                }
                            }
                        }
                    } else if (uri.getScheme().equals("file")) {
                        Path pathObject = Paths.get(uri);
                        if (Files.isDirectory(pathObject)) {
                            return Optional.empty();
                        }
                        return Optional.of(Files.newInputStream(pathObject));
                    }
                } catch (URISyntaxException | IOException | ProviderNotFoundException e) {
                    if (LOG.isDebugEnabled()) {
                        LOG.debug("Error establishing whether path is a directory: " + e.getMessage(), e);
                    }
                }
            }
        }
        // fallback to less sophisticated approach
        if (path.indexOf('.') == -1) {
            return Optional.empty();
        }
        final URL u = getResource(path).orElse(null);
        if (u != null) {
            try {
                return Optional.of(u.openStream());
            } catch (IOException e) {
                // fallback to empty
            }
        }
        return Optional.empty();
    }