类java.nio.file.FileSystemNotFoundException源码实例Demo

下面列出了怎么用java.nio.file.FileSystemNotFoundException的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: vind   文件: ElasticMappingUtils.java
private static FileSystem getFileSystem(URI jarUri) {
    FileSystem fs = fileSystems.get(jarUri);
    if (fs == null) {
        synchronized (fileSystems) {
            fs = fileSystems.get(jarUri);
            if (fs == null) {
                try {
                    fs = FileSystems.getFileSystem(jarUri);
                } catch (FileSystemNotFoundException e1) {
                    try {
                        fs = FileSystems.newFileSystem(jarUri, Collections.emptyMap());
                    } catch (IOException e2) {
                        throw new IllegalStateException("Could not create FileSystem for " + jarUri, e2);
                    }
                }
                fileSystems.put(jarUri, fs);
            }
        }
    }
    return fs;
}
 
源代码2 项目: openjdk-jdk9   文件: SystemImage.java
static SystemImage open() throws IOException {
    if (modulesImageExists) {
        // open a .jimage and build directory structure
        final ImageReader image = ImageReader.open(moduleImageFile);
        image.getRootDirectory();
        return new SystemImage() {
            @Override
            Node findNode(String path) throws IOException {
                return image.findNode(path);
            }
            @Override
            byte[] getResource(Node node) throws IOException {
                return image.getResource(node);
            }
            @Override
            void close() throws IOException {
                image.close();
            }
        };
    }
    if (Files.notExists(explodedModulesDir))
        throw new FileSystemNotFoundException(explodedModulesDir.toString());
    return new ExplodedImage(explodedModulesDir);
}
 
源代码3 项目: manifold   文件: PathUtil.java
public static Path create( URI uri )
{
  try
  {
    return Paths.get( uri );
  }
  catch( FileSystemNotFoundException nfe )
  {
    try
    {
      Map<String, String> env = new HashMap<>();
      env.put( "create", "true" ); // creates zip/jar file if not already exists
      FileSystem fs = FileSystems.newFileSystem( uri, env );
      return fs.provider().getPath( uri );
    }
    catch( IOException e )
    {
      throw new RuntimeException( e );
    }
  }
}
 
源代码4 项目: synthea   文件: Module.java
private static void fixPathFromJar(URI uri) throws IOException {
  // this function is a hack to enable reading modules from within a JAR file
  // see https://stackoverflow.com/a/48298758
  if ("jar".equals(uri.getScheme())) {
    for (FileSystemProvider provider: FileSystemProvider.installedProviders()) {
      if (provider.getScheme().equalsIgnoreCase("jar")) {
        try {
          provider.getFileSystem(uri);
        } catch (FileSystemNotFoundException e) {
          // in this case we need to initialize it first:
          provider.newFileSystem(uri, Collections.emptyMap());
        }
      }
    }
  }
}
 
源代码5 项目: huntbugs   文件: Repository.java
static Repository createDetectorsRepo(Class<?> clazz, String pluginName, Set<Path> paths) {
    CodeSource codeSource = clazz.getProtectionDomain().getCodeSource();
    if (codeSource == null) {
        throw new RuntimeException(format("Initializing plugin '%s' could not get code source for class %s", pluginName, clazz.getName()));
    }

    URL url = codeSource.getLocation();
    try {
        Path path = Paths.get(url.toURI());
        if(paths.add(path)) {
            if(Files.isDirectory(path)) {
                return new DirRepository(path);
            } else {
                return new JarRepository(new JarFile(path.toFile()));
            }
        } else {
            return createNullRepository();
        }
    } catch (URISyntaxException | FileSystemNotFoundException | IllegalArgumentException
            | IOException | UnsupportedOperationException e) {
        String errorMessage = format("Error creating detector repository for plugin '%s'", pluginName);
        throw new RuntimeException(errorMessage, e);
    }
}
 
源代码6 项目: mycore   文件: MCRIView2Tools.java
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);
    }
}
 
源代码7 项目: mycore   文件: MCRAbstractFileSystem.java
/**
 * Returns any subclass that implements and handles the given scheme.
 * @param scheme a valid {@link URI} scheme
 * @see FileSystemProvider#getScheme()
 * @throws FileSystemNotFoundException if no filesystem handles this scheme
 */
public static MCRAbstractFileSystem getInstance(String scheme) {
    URI uri;
    try {
        uri = MCRPaths.getURI(scheme, "helper", SEPARATOR_STRING);
    } catch (URISyntaxException e) {
        throw new MCRException(e);
    }
    for (FileSystemProvider provider : Iterables.concat(MCRPaths.webAppProvider,
        FileSystemProvider.installedProviders())) {
        if (provider.getScheme().equals(scheme)) {
            return (MCRAbstractFileSystem) provider.getFileSystem(uri);
        }
    }
    throw new FileSystemNotFoundException("Provider \"" + scheme + "\" not found");
}
 
源代码8 项目: mycore   文件: MCRFileSystemProvider.java
@Override
public Path getPath(final URI uri) {
    if (!FS_URI.getScheme().equals(Objects.requireNonNull(uri).getScheme())) {
        throw new FileSystemNotFoundException("Unkown filesystem: " + uri);
    }
    String path = uri.getPath().substring(1);//URI path is absolute -> remove first slash
    String owner = null;
    for (int i = 0; i < path.length(); i++) {
        if (path.charAt(i) == MCRAbstractFileSystem.SEPARATOR) {
            break;
        }
        if (path.charAt(i) == ':') {
            owner = path.substring(0, i);
            path = path.substring(i + 1);
            break;
        }

    }
    return MCRAbstractFileSystem.getPath(owner, path, getFileSystemFromPathURI(FS_URI));
}
 
源代码9 项目: mycore   文件: MCRFileSystemProvider.java
@Override
public Path getPath(final URI uri) {
    if (!FS_URI.getScheme().equals(Objects.requireNonNull(uri).getScheme())) {
        throw new FileSystemNotFoundException("Unkown filesystem: " + uri);
    }
    String path = uri.getPath().substring(1);//URI path is absolute -> remove first slash
    String owner = null;
    for (int i = 0; i < path.length(); i++) {
        if (path.charAt(i) == MCRAbstractFileSystem.SEPARATOR) {
            break;
        }
        if (path.charAt(i) == ':') {
            owner = path.substring(0, i);
            path = path.substring(i + 1);
            break;
        }

    }
    return MCRAbstractFileSystem.getPath(owner, path, getFileSystemFromPathURI(FS_URI));
}
 
源代码10 项目: baratine   文件: JFileSystemProvider.java
private JFileSystem getLocalSystem()
{
  synchronized (_localSystem) {
    JFileSystem localSystem = _localSystem.getLevel();
    
    if (localSystem == null) {
      BartenderFileSystem fileSystem = BartenderFileSystem.getCurrent();

      if (fileSystem == null) {
        throw new FileSystemNotFoundException(L.l("cannot find local bfs file system"));
      }

      ServiceRef root = fileSystem.getRootServiceRef();

      localSystem = new JFileSystem(this, root);
      
      _localSystem.set(localSystem);
    }
    
    return localSystem;
  }
}
 
源代码11 项目: sftp-fs   文件: SFTPFileSystemProviderTest.java
@Test
public void testRemoveFileSystem() throws IOException {
    addDirectory("/foo/bar");

    SFTPFileSystemProvider provider = new SFTPFileSystemProvider();
    URI uri;
    try (SFTPFileSystem fs = newFileSystem(provider, createEnv())) {
        SFTPPath path = new SFTPPath(fs, "/foo/bar");

        uri = path.toUri();

        assertFalse(provider.isHidden(path));
    }
    FileSystemNotFoundException exception = assertThrows(FileSystemNotFoundException.class, () -> provider.getPath(uri));
    assertEquals(uri.toString(), exception.getMessage());
}
 
源代码12 项目: tiny-remapper   文件: FileSystemHandler.java
public static synchronized FileSystem open(URI uri) throws IOException {
	FileSystem ret = null;

	try {
		ret = FileSystems.getFileSystem(uri);
	} catch (FileSystemNotFoundException e) { }

	boolean opened;

	if (ret == null) {
		ret = FileSystems.newFileSystem(uri, Collections.emptyMap());
		opened = true;
	} else {
		opened = false;
	}

	RefData data = fsRefs.get(ret);

	if (data == null) {
		fsRefs.put(ret, new RefData(opened, 1));
	} else {
		data.refs++;
	}

	return ret;
}
 
@Override
public BundleFileSystem getFileSystem(URI uri) {
	synchronized (openFilesystems) {
		URI baseURI = baseURIFor(uri);
		WeakReference<BundleFileSystem> ref = openFilesystems.get(baseURI);
		if (ref == null) {
			throw new FileSystemNotFoundException(uri.toString());
		}
		BundleFileSystem fs = ref.get();
		if (fs == null) {
			openFilesystems.remove(baseURI);
			throw new FileSystemNotFoundException(uri.toString());
		}
		return fs;
	}
}
 
源代码14 项目: Hadoop-BAM   文件: NIOFileUtil.java
/**
 * Convert the given path {@link URI} to a {@link Path} object.
 * @param uri the path to convert
 * @return a {@link Path} object
 */
public static Path asPath(URI uri) {
  try {
    return Paths.get(uri);
  } catch (FileSystemNotFoundException e) {
    ClassLoader cl = Thread.currentThread().getContextClassLoader();
    if (cl == null) {
      throw e;
    }
    try {
      return FileSystems.newFileSystem(uri, new HashMap<>(), cl).provider().getPath(uri);
    } catch (IOException ex) {
      throw new RuntimeException("Cannot create filesystem for " + uri, ex);
    }
  }
}
 
源代码15 项目: ParallelGit   文件: PathsTest.java
@Test(expected = FileSystemNotFoundException.class)
public void getArbitraryFileFromUri_invalidSid() {
  URI uri = GfsUriBuilder.fromFileSystem(gfs)
              .file("/test_file.txt")
              .sid("some_invalid_sid").build();
  Paths.get(uri);
}
 
源代码16 项目: encfs4j   文件: EncryptedFileSystemProvider.java
@Override
public FileSystem getFileSystem(URI uri) {
	assertUri(uri);
	FileSystem result = encFileSystem;
	if (result == null)
		throw new FileSystemNotFoundException();
	return result;
}
 
public void scanSystemModules() throws IOException {
    try (DirectoryStream<Path> moduleStream = Files.newDirectoryStream(Paths.get(URI.create("jrt:/modules")))) {
        for (Path module : moduleStream) {
            scanTree(module);
        }
    } catch (FileSystemNotFoundException e) {
        // Modules are not supported
    }
}
 
源代码18 项目: dragonwell8_jdk   文件: FaultyFileSystem.java
@Override
public FileSystem getFileSystem(URI uri) {
    checkUri(uri);
    FileSystem result = delegate;
    if (result == null)
        throw new FileSystemNotFoundException();
    return result;
}
 
源代码19 项目: dragonwell8_jdk   文件: FaultyFileSystem.java
@Override
public Path getPath(URI uri) {
    checkScheme(uri);
    if (delegate == null)
        throw new FileSystemNotFoundException();

    // only allow absolute path
    String path = uri.getSchemeSpecificPart();
    if (! path.startsWith("///")) {
        throw new IllegalArgumentException();
    }
    return new PassThroughFileSystem.PassThroughPath(delegate, delegate.root.resolve(path.substring(3)));
}
 
源代码20 项目: TencentKona-8   文件: FaultyFileSystem.java
@Override
public FileSystem getFileSystem(URI uri) {
    checkUri(uri);
    FileSystem result = delegate;
    if (result == null)
        throw new FileSystemNotFoundException();
    return result;
}
 
源代码21 项目: TencentKona-8   文件: FaultyFileSystem.java
@Override
public Path getPath(URI uri) {
    checkScheme(uri);
    if (delegate == null)
        throw new FileSystemNotFoundException();

    // only allow absolute path
    String path = uri.getSchemeSpecificPart();
    if (! path.startsWith("///")) {
        throw new IllegalArgumentException();
    }
    return new PassThroughFileSystem.PassThroughPath(delegate, delegate.root.resolve(path.substring(3)));
}
 
源代码22 项目: jdk8u60   文件: FaultyFileSystem.java
@Override
public FileSystem getFileSystem(URI uri) {
    checkUri(uri);
    FileSystem result = delegate;
    if (result == null)
        throw new FileSystemNotFoundException();
    return result;
}
 
源代码23 项目: jdk8u60   文件: FaultyFileSystem.java
@Override
public Path getPath(URI uri) {
    checkScheme(uri);
    if (delegate == null)
        throw new FileSystemNotFoundException();

    // only allow absolute path
    String path = uri.getSchemeSpecificPart();
    if (! path.startsWith("///")) {
        throw new IllegalArgumentException();
    }
    return new PassThroughFileSystem.PassThroughPath(delegate, delegate.root.resolve(path.substring(3)));
}
 
源代码24 项目: halo   文件: PathTest.java
@Test(expected = FileSystemNotFoundException.class)
public void getPathOfJarFileFailure() throws URISyntaxException {
    String file = "jar:file:/path/to/jar/xxx.jar!/BOOT-INF/classes!/templates/themes";
    URI uri = new URI(file);
    Path path = Paths.get(uri);

    log.debug("Path: " + path.toString());
}
 
源代码25 项目: openjdk-jdk8u   文件: FaultyFileSystem.java
@Override
public FileSystem getFileSystem(URI uri) {
    checkUri(uri);
    FileSystem result = delegate;
    if (result == null)
        throw new FileSystemNotFoundException();
    return result;
}
 
源代码26 项目: openjdk-jdk8u   文件: FaultyFileSystem.java
@Override
public Path getPath(URI uri) {
    checkScheme(uri);
    if (delegate == null)
        throw new FileSystemNotFoundException();

    // only allow absolute path
    String path = uri.getSchemeSpecificPart();
    if (! path.startsWith("///")) {
        throw new IllegalArgumentException();
    }
    return new PassThroughFileSystem.PassThroughPath(delegate, delegate.root.resolve(path.substring(3)));
}
 
源代码27 项目: ocr-neuralnet   文件: NativeUtils.java
private static boolean isPosixCompliant() {
    try {
        return FileSystems.getDefault()
                .supportedFileAttributeViews()
                .contains("posix");
    } catch (FileSystemNotFoundException
            | ProviderNotFoundException
            | SecurityException e) {
        return false;
    }
}
 
源代码28 项目: openjdk-jdk8u-backup   文件: FaultyFileSystem.java
@Override
public FileSystem getFileSystem(URI uri) {
    checkUri(uri);
    FileSystem result = delegate;
    if (result == null)
        throw new FileSystemNotFoundException();
    return result;
}
 
源代码29 项目: openjdk-jdk8u-backup   文件: FaultyFileSystem.java
@Override
public Path getPath(URI uri) {
    checkScheme(uri);
    if (delegate == null)
        throw new FileSystemNotFoundException();

    // only allow absolute path
    String path = uri.getSchemeSpecificPart();
    if (! path.startsWith("///")) {
        throw new IllegalArgumentException();
    }
    return new PassThroughFileSystem.PassThroughPath(delegate, delegate.root.resolve(path.substring(3)));
}
 
源代码30 项目: encfs4j   文件: EncryptedFileSystemProvider.java
@Override
public Path getPath(URI uri) {
	assertUriScheme(uri);
	if (encFileSystem == null)
		throw new FileSystemNotFoundException();

	// avoid unterminated recursion / to be able to run Paths.get(URI)
	uri = URI.create(encFileSystem.getSubFileSystem().provider()
			.getScheme()
			+ ":" + uri.getSchemeSpecificPart());
	return new EncryptedFileSystemPath(encFileSystem, encFileSystem
			.getSubFileSystem().provider().getPath(uri));
}
 
 类所在包
 同包方法