001/*
002 * SPDX-License-Identifier: Apache-2.0
003 *
004 * Copyright 2024-2026 The Enola <https://enola.dev> Authors
005 *
006 * Licensed under the Apache License, Version 2.0 (the "License");
007 * you may not use this file except in compliance with the License.
008 * You may obtain a copy of the License at
009 *
010 *     https://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package dev.enola.common.io;
019
020import com.google.common.collect.ImmutableSet;
021
022import java.nio.file.FileSystem;
023import java.nio.file.FileSystems;
024import java.nio.file.spi.FileSystemProvider;
025
026/** Utilities for {@link FileSystem}, similar to {@link FileSystems}. */
027public final class MoreFileSystems {
028    private MoreFileSystems() {}
029
030    /** Set of registered FileSystem schemas; e.g. "file" (for "file:///...") and "jar" etc. */
031    public static final ImmutableSet<String> URI_SCHEMAS = getFileSystemSchemes();
032
033    private static ImmutableSet<String> getFileSystemSchemes() {
034        var builder = ImmutableSet.<String>builder();
035        for (FileSystemProvider provider : FileSystemProvider.installedProviders()) {
036            // TODO Add full support for the jar: FileSystem? It's intentionally not supported,
037            // yet... because it would need more work; see
038            // https://stackoverflow.com/q/25032716/421602
039            // https://docs.oracle.com/javase/7/docs/technotes/guides/io/fsp/zipfilesystemprovider.html
040            // https://docs.oracle.com/en/java/javase/21/docs/api/jdk.zipfs/module-summary.html
041            if (!provider.getScheme().equals("jar")) {
042                builder.add(provider.getScheme());
043            }
044        }
045        return builder.build();
046    }
047}