Java Code Examples for java.nio.file.FileSystemAlreadyExistsException

The following examples show how to use java.nio.file.FileSystemAlreadyExistsException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
        delegate = result;
        return result;
    }
}
 
Example 2
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    checkUri(uri);
    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(null);
        delegate = result;
        return result;
    }
}
 
Example 3
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
        delegate = result;
        return result;
    }
}
 
Example 4
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    checkUri(uri);
    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(null);
        delegate = result;
        return result;
    }
}
 
Example 5
Source Project: jdk8u60   Source File: FaultyFileSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
        delegate = result;
        return result;
    }
}
 
Example 6
Source Project: jdk8u60   Source File: FaultyFileSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    checkUri(uri);
    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(null);
        delegate = result;
        return result;
    }
}
 
Example 7
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
        delegate = result;
        return result;
    }
}
 
Example 8
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    checkUri(uri);
    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(null);
        delegate = result;
        return result;
    }
}
 
Example 9
/**
 * Get the URI of the specified configuration file from its resolved URL.
 * 
 * @param path configuration file path (absolute, relative, or simple filename)
 * @param url resolved configuration file URL
 * @return resolved configuration file URI 
 * @throws URISyntaxException if specified URL is invalid
 * @throws IOException on failure to construct file system or extract configuration file
 */
private static URI getConfigUri(final String path, final URL url) throws URISyntaxException, IOException {
    URI uri = url.toURI();
    if ("jar".equals(uri.getScheme())) {
        try {
            FileSystems.newFileSystem(uri, Collections.<String, Object>emptyMap());
        } catch (FileSystemAlreadyExistsException eaten) { //NOSONAR
            LOGGER.warn("Specified file system already exists: {}", eaten.getMessage());
        } 
        
        String outputDir = PathUtils.getBaseDir();
        File outputFile = new File(outputDir, path);
        Path outputPath = outputFile.toPath();
        if (!outputPath.toFile().exists()) {
            Files.copy(Paths.get(uri), outputPath);
        }
        uri = outputPath.toUri();
    }
    return uri;
}
 
Example 10
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
        delegate = result;
        return result;
    }
}
 
Example 11
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    checkUri(uri);
    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(null);
        delegate = result;
        return result;
    }
}
 
Example 12
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
        delegate = result;
        return result;
    }
}
 
Example 13
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    checkUri(uri);
    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(null);
        delegate = result;
        return result;
    }
}
 
Example 14
Source Project: jdk8u-jdk   Source File: FaultyFileSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
        delegate = result;
        return result;
    }
}
 
Example 15
Source Project: jdk8u-jdk   Source File: FaultyFileSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    checkUri(uri);
    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(null);
        delegate = result;
        return result;
    }
}
 
Example 16
Source Project: hottub   Source File: FaultyFileSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
        delegate = result;
        return result;
    }
}
 
Example 17
Source Project: hottub   Source File: FaultyFileSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    checkUri(uri);
    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(null);
        delegate = result;
        return result;
    }
}
 
Example 18
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
        delegate = result;
        return result;
    }
}
 
Example 19
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    checkUri(uri);
    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(null);
        delegate = result;
        return result;
    }
}
 
Example 20
Source Project: mycore   Source File: MCRIView2Tools.java    License: GNU General Public License v3.0 6 votes vote down vote up
public static FileSystem getFileSystem(Path iviewFile) throws IOException {
    URI uri = URI.create("jar:" + iviewFile.toUri());
    try {
        return FileSystems.newFileSystem(uri, Collections.emptyMap(), MCRClassTools.getClassLoader());
    } catch (FileSystemAlreadyExistsException exc) {
        // block until file system is closed
        try {
            FileSystem fileSystem = FileSystems.getFileSystem(uri);
            while (fileSystem.isOpen()) {
                try {
                    Thread.sleep(10);
                } catch (InterruptedException ie) {
                    // get out of here
                    throw new IOException(ie);
                }
            }
        } catch (FileSystemNotFoundException fsnfe) {
            // seems closed now -> do nothing and try to return the file system again
            LOGGER.debug("Filesystem not found", fsnfe);
        }
        return getFileSystem(iviewFile);
    }
}
 
Example 21
Source Project: sftp-fs   Source File: SFTPFileSystemProvider.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Constructs a new {@code FileSystem} object identified by a URI.
 * <p>
 * The URI must have a {@link URI#getScheme() scheme} equal to {@link #getScheme()}, and no {@link URI#getUserInfo() user information},
 * {@link URI#getPath() path}, {@link URI#getQuery() query} or {@link URI#getFragment() fragment}. Authentication credentials must be set through
 * the given environment map, preferably through {@link SFTPEnvironment}.
 * <p>
 * This provider allows multiple file systems per host, but only one file system per user on a host.
 * Once a file system is {@link FileSystem#close() closed}, this provider allows a new file system to be created with the same URI and credentials
 * as the closed file system.
 */
@Override
@SuppressWarnings("resource")
public FileSystem newFileSystem(URI uri, Map<String, ?> env) throws IOException {
    // user info must come from the environment map
    checkURI(uri, false, false);

    SFTPEnvironment environment = wrapEnvironment(env);

    String username = environment.getUsername();
    URI normalizedURI = normalizeWithUsername(uri, username);
    synchronized (fileSystems) {
        if (fileSystems.containsKey(normalizedURI)) {
            throw new FileSystemAlreadyExistsException(normalizedURI.toString());
        }

        SFTPFileSystem fs = new SFTPFileSystem(this, normalizedURI, environment);
        fileSystems.put(normalizedURI, fs);
        return fs;
    }
}
 
Example 22
Source Project: openjdk-8   Source File: FaultyFileSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
        delegate = result;
        return result;
    }
}
 
Example 23
Source Project: openjdk-8   Source File: FaultyFileSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    checkUri(uri);
    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(null);
        delegate = result;
        return result;
    }
}
 
Example 24
Source Project: jdk8u_jdk   Source File: FaultyFileSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
        delegate = result;
        return result;
    }
}
 
Example 25
Source Project: jdk8u_jdk   Source File: FaultyFileSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    checkUri(uri);
    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(null);
        delegate = result;
        return result;
    }
}
 
Example 26
Source Project: che   Source File: IoUtil.java    License: Eclipse Public License 2.0 6 votes vote down vote up
/**
 * Lists all children resources.
 *
 * @param parent the root path represented in {@link URI} format
 * @param consumer consumer for children resources
 * @throws java.io.IOException if any i/o error occur
 * @throws ProviderNotFoundException if a provider supporting the URI scheme is not installed
 */
public static void listResources(URI parent, Consumer<Path> consumer) throws IOException {
  FileSystem fileSystem = null;
  try {
    if (!"file".equals(parent.getScheme())) {
      try {
        fileSystem = FileSystems.newFileSystem(parent, Collections.emptyMap());
      } catch (FileSystemAlreadyExistsException ignore) {
      }
    }

    Path root = Paths.get(parent);
    Files.list(root).forEach(consumer);
  } finally {
    // close FS only if only it has been initialized here
    if (fileSystem != null) {
      fileSystem.close();
    }
  }
}
 
Example 27
Source Project: jdk8u-jdk   Source File: FaultyFileSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
        delegate = result;
        return result;
    }
}
 
Example 28
Source Project: jdk8u-jdk   Source File: FaultyFileSystem.java    License: GNU General Public License v2.0 6 votes vote down vote up
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    checkUri(uri);
    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(null);
        delegate = result;
        return result;
    }
}
 
Example 29
@Override
public FileSystem newFileSystem(Path fakeRoot, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(fakeRoot);
        delegate = result;
        return result;
    }
}
 
Example 30
@Override
public FileSystem newFileSystem(URI uri, Map<String,?> env)
    throws IOException
{
    if (env != null && env.keySet().contains("IOException")) {
        triggerEx("IOException");
    }

    checkUri(uri);
    synchronized (FaultyFSProvider.class) {
        if (delegate != null && delegate.isOpen())
            throw new FileSystemAlreadyExistsException();
        FaultyFileSystem result = new FaultyFileSystem(null);
        delegate = result;
        return result;
    }
}