<commit_before>/*
* JBoss, Home of Professional Open Source
* Copyright 2006, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.vfs;

import java.io.Closeable;
import java.io.IOException;
import java.io.File;
import java.io.InputStream;
import java.io.FileOutputStream;
import java.net.URI;
import java.net.URL;
import java.net.URISyntaxException;
import java.util.AbstractSet;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.security.AccessController;
import java.security.PrivilegedAction;

import org.jboss.vfs.spi.AssemblyFileSystem;
import org.jboss.vfs.spi.FileSystem;
import org.jboss.vfs.spi.RealFileSystem;
import org.jboss.vfs.spi.JavaZipFileSystem;
import org.jboss.logging.Logger;
import org.jboss.net.protocol.URLStreamHandlerFactory;

/**
 * Virtual File System
 *
 * @author <a href="<EMAIL>"><NAME></a>
 * @author <EMAIL>
 * @author <a href="<EMAIL>"><NAME></a>
 * @version $Revision: 1.1 $
 */
public class VFS {

    private static final Logger log = Logger.getLogger("org.jboss.vfs");

    public static final boolean LEAK_DEBUGGING;
    public static final boolean FORCE_CANONICAL;

    private static final ConcurrentMap<VirtualFile, Map<String, Mount>> mounts = new ConcurrentHashMap<VirtualFile, Map<String, Mount>>();
    private static final VirtualFile rootVirtualFile = new VirtualFile("", null);
    private static final Mount rootMount = new Mount(RealFileSystem.ROOT_INSTANCE, rootVirtualFile);

    // todo - LRU VirtualFiles?
    // todo - LRU String intern?
    static {
        init();
        LEAK_DEBUGGING = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
            public Boolean run() {
                return Boolean.valueOf(System.getProperty("jboss.vfs.leakDebugging", "true"));
            }
        });
        FORCE_CANONICAL = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
            public Boolean run() {
                return Boolean.getBoolean("jboss.vfs.forceCanonical");
            }
        });

        if (FORCE_CANONICAL)
           log.info("Canonical path lookup enabled.");
    }

    /**
     * Do not allow construction 
     */
    private VFS() {
    }
    
    /**
     * Initialize VFS protocol handlers package property.
     */
    private static void init() {
        // If this doesn't work, hopefully the existing URLStreamHandlerFactory supports updates to the 'java.protocol.handler.pkgs' property.
        try {
           URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory());
        } catch (Throwable ignored) {}

        String pkgs = System.getProperty("java.protocol.handler.pkgs");
        if (pkgs == null || pkgs.trim().length() == 0) {
            pkgs = "org.jboss.net.protocol|org.jboss.vfs.protocol";
            System.setProperty("java.protocol.handler.pkgs", pkgs);
        } else if (pkgs.contains("org.jboss.vfs.protocol") == false) {
            if(pkgs.contains("org.jboss.net.protocol") == false)
                pkgs += "|org.jboss.net.protocol";
            pkgs += "|org.jboss.vfs.protocol";
            System.setProperty("java.protocol.handler.pkgs", pkgs);
        }
    }

    /**
     * Mount a filesystem on a mount point in the VFS.  The mount point is any valid file name, existant or non-existant.
     * If a relative path is given, it will be treated as relative to the VFS root.
     *
     * @param mountPoint the mount point
     * @param fileSystem the file system to mount
     *
     * @return a handle which can be used to unmount the filesystem
     *
     * @throws IOException if an I/O error occurs, such as a filesystem already being mounted at the given mount point<commit_msg>[JBVFS-141] - Give warning when VFS can not register URLStreamHandlerFactory<commit_after>/*
* JBoss, Home of Professional Open Source
* Copyright 2006, JBoss Inc., and individual contributors as indicated
* by the @authors tag. See the copyright.txt in the distribution for a
* full listing of individual contributors.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
*/
package org.jboss.vfs;

import java.io.Closeable;
import java.io.IOException;
import java.io.File;
import java.io.InputStream;
import java.io.FileOutputStream;
import java.net.URI;
import java.net.URL;
import java.net.URISyntaxException;
import java.util.AbstractSet;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.atomic.AtomicBoolean;
import java.security.AccessController;
import java.security.PrivilegedAction;

import org.jboss.vfs.spi.AssemblyFileSystem;
import org.jboss.vfs.spi.FileSystem;
import org.jboss.vfs.spi.RealFileSystem;
import org.jboss.vfs.spi.JavaZipFileSystem;
import org.jboss.logging.Logger;
import org.jboss.net.protocol.URLStreamHandlerFactory;

/**
 * Virtual File System
 *
 * @author <a href="<EMAIL>"><NAME></a>
 * @author <EMAIL>
 * @author <a href="<EMAIL>"><NAME></a>
 * @version $Revision: 1.1 $
 */
public class VFS {

    private static final Logger log = Logger.getLogger("org.jboss.vfs");

    public static final boolean LEAK_DEBUGGING;
    public static final boolean FORCE_CANONICAL;

    private static final ConcurrentMap<VirtualFile, Map<String, Mount>> mounts = new ConcurrentHashMap<VirtualFile, Map<String, Mount>>();
    private static final VirtualFile rootVirtualFile = new VirtualFile("", null);
    private static final Mount rootMount = new Mount(RealFileSystem.ROOT_INSTANCE, rootVirtualFile);

    // todo - LRU VirtualFiles?
    // todo - LRU String intern?
    static {
        init();
        LEAK_DEBUGGING = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
            public Boolean run() {
                return Boolean.valueOf(System.getProperty("jboss.vfs.leakDebugging", "true"));
            }
        });
        FORCE_CANONICAL = AccessController.doPrivileged(new PrivilegedAction<Boolean>() {
            public Boolean run() {
                return Boolean.getBoolean("jboss.vfs.forceCanonical");
            }
        });

        if (FORCE_CANONICAL)
           log.info("Canonical path lookup enabled.");
    }

    /**
     * Do not allow construction 
     */
    private VFS() {
    }
    
    /**
     * Initialize VFS protocol handlers package property.
     */
    private static void init() {
        // If this doesn't work, hopefully the existing URLStreamHandlerFactory supports updates to the 'java.protocol.handler.pkgs' property.
        try {
           URL.setURLStreamHandlerFactory(new URLStreamHandlerFactory());
        } catch (Throwable ignored) {
           log.warn("VFS was unable to set the URLStreamHandlerFactory.  This will have unpredictable results");
        }

        String pkgs = System.getProperty("java.protocol.handler.pkgs");
        if (pkgs == null || pkgs.trim().length() == 0) {
            pkgs = "org.jboss.net.protocol|org.jboss.vfs.protocol";
            System.setProperty("java.protocol.handler.pkgs", pkgs);
        } else if (pkgs.contains("org.jboss.vfs.protocol") == false) {
            if(pkgs.contains("org.jboss.net.protocol") == false)
                pkgs += "|org.jboss.net.protocol";
            pkgs += "|org.jboss.vfs.protocol";
            System.setProperty("java.protocol.handler.pkgs", pkgs);
        }
    }

    /**
     * Mount a filesystem on a mount point in the VFS.  The mount point is any valid file name, existant or non-existant.
     * If a relative path is given, it will be treated as relative to the VFS root.
     *
     * @param mountPoint the mount point
     * @param fileSystem the file system to mount
     *
     * @return a handle which can be used to unmount the filesystem
     *
     * @throws IOException if an I/O error occurs, such as a filesystem already being mounted at the given mount point
{'fraction_non_alphanumeric': 0.10077832811078541, 'fraction_numerical': 0.004346507631658748, 'mean_word_length': 3.259147653895824, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6422073', 'n_tokens_mistral': 2885, 'n_tokens_neox': 2770, 'n_words': 905}