Java 类java.nio.file.FileSystemAlreadyExistsException 实例源码

项目:jdk8u-jdk    文件:FaultyFileSystem.java   
@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;
    }
}
项目:jdk8u-jdk    文件:FaultyFileSystem.java   
@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;
    }
}
项目:openjdk-jdk10    文件:FaultyFileSystem.java   
@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;
    }
}
项目:openjdk-jdk10    文件:FaultyFileSystem.java   
@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;
    }
}
项目:openjdk9    文件:FaultyFileSystem.java   
@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;
    }
}
项目:openjdk9    文件:FaultyFileSystem.java   
@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;
    }
}
项目: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(),
            MCRIView2Tools.class.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);
    }
}
项目:jdk8u_jdk    文件:FaultyFileSystem.java   
@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;
    }
}
项目:jdk8u_jdk    文件:FaultyFileSystem.java   
@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;
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:FaultyFileSystem.java   
@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;
    }
}
项目:lookaside_java-1.8.0-openjdk    文件:FaultyFileSystem.java   
@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;
    }
}
项目:che    文件:IoUtil.java   
/**
 * 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();
    }
  }
}
项目:infobip-open-jdk-8    文件:FaultyFileSystem.java   
@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;
    }
}
项目:infobip-open-jdk-8    文件:FaultyFileSystem.java   
@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;
    }
}
项目:jdk8u-dev-jdk    文件:FaultyFileSystem.java   
@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;
    }
}
项目:jdk8u-dev-jdk    文件:FaultyFileSystem.java   
@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;
    }
}
项目:archive-fs    文件:AbstractTarFileSystemProvider.java   
@Override
public FileSystem newFileSystem(URI uri, Map<String, ?> env)
        throws IOException {
    Path path = uriToPath(uri);
    synchronized (filesystems) {
        Path realPath = null;
        if (ensureFile(path)) {
            realPath = path.toRealPath();
            if (filesystems.containsKey(realPath)) {
                throw new FileSystemAlreadyExistsException();
            }
        }
        AbstractTarFileSystem tarfs = null;
        tarfs = newInstance(this, path, env);
        filesystems.put(realPath, tarfs);
        return tarfs;
    }
}
项目:OLD-OpenJDK8    文件:FaultyFileSystem.java   
@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;
    }
}
项目:OLD-OpenJDK8    文件:FaultyFileSystem.java   
@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;
    }
}
项目:jimfs    文件:SystemJimfsFileSystemProvider.java   
@Override
public FileSystem newFileSystem(URI uri, Map<String, ?> env) throws IOException {
  checkArgument(
      uri.getScheme().equalsIgnoreCase(URI_SCHEME),
      "uri (%s) scheme must be '%s'",
      uri,
      URI_SCHEME);
  checkArgument(
      isValidFileSystemUri(uri), "uri (%s) may not have a path, query or fragment", uri);
  checkArgument(
      env.get(FILE_SYSTEM_KEY) instanceof FileSystem,
      "env map (%s) must contain key '%s' mapped to an instance of %s",
      env, FILE_SYSTEM_KEY, FileSystem.class);

  FileSystem fileSystem = (FileSystem) env.get(FILE_SYSTEM_KEY);
  if (fileSystems.putIfAbsent(uri, fileSystem) != null) {
    throw new FileSystemAlreadyExistsException(uri.toString());
  }
  return fileSystem;
}
项目:raml-module-builder    文件:ResourceUtils.java   
private static FileSystem getFileSystem(URI uri) throws IOException {
  try {
    return FileSystems.newFileSystem(uri, Collections.<String, Object> emptyMap());
  } catch (FileSystemAlreadyExistsException e) {
    return FileSystems.getFileSystem(uri);
  }
}
项目:raml-module-builder    文件:Messages.java   
private FileSystem getFileSystem(URI uri) throws IOException {
  try {
    return FileSystems.newFileSystem(uri, Collections.<String, Object> emptyMap());
  } catch (FileSystemAlreadyExistsException e) { // NOSONAR
    return FileSystems.getFileSystem(uri);
  }
}
项目:incubator-taverna-language    文件:BundleFileSystemProvider.java   
@Override
public BundleFileSystem newFileSystem(URI uri, Map<String, ?> env)
        throws IOException {

    Path localPath = localPathFor(uri);
    URI baseURI = baseURIFor(uri);

    if (asBoolean(env.get("create"), false)) {
        createBundleAsZip(localPath, (String) env.get("mimetype"));
    }

    BundleFileSystem fs;
    synchronized (openFilesystems) {
        WeakReference<BundleFileSystem> existingRef = openFilesystems
                .get(baseURI);
        if (existingRef != null) {
            BundleFileSystem existing = existingRef.get();
            if (existing != null && existing.isOpen()) {
                throw new FileSystemAlreadyExistsException(
                        baseURI.toASCIIString());
            }
        }
        FileSystem origFs = FileSystems.newFileSystem(localPath, null);
        fs = new BundleFileSystem(origFs, baseURI);
        openFilesystems.put(baseURI,
                new WeakReference<BundleFileSystem>(fs));
    }
    return fs;
}
项目:ephemeralfs    文件:EphemeralFsFileSystemProvider.java   
@Override
public FileSystem newFileSystem(URI uri, Map<String, ?> env)
        throws IOException {

    if (uri == null || env == null) {
        throw new NullPointerException();
    }
    String name = validateUriAndGetName(uri);
    EphemeralFsFileSystem answer = new EphemeralFsFileSystem(name, new Settings(env), this);
    if (fileSystems.putIfAbsent(name, answer) != null) {
        throw new FileSystemAlreadyExistsException(
                "A filesystem already exists with the name:" + name);
    }
    return answer;
}
项目:kurento-module-creator    文件:PathUtils.java   
public static Path getPathInClasspath(URL resource) throws IOException, URISyntaxException {

    Objects.requireNonNull(resource, "Resource URL cannot be null");
    URI uri = resource.toURI();

    String scheme = uri.getScheme();
    if (scheme.equals("file")) {
      return Paths.get(uri);
    }

    if (!scheme.equals("jar")) {
      throw new IllegalArgumentException("Cannot convert to Path: " + uri);
    }

    String uriStr = uri.toString();
    int separator = uriStr.indexOf("!/");
    String entryName = uriStr.substring(separator + 2);
    URI fileUri = URI.create(uriStr.substring(0, separator));

    FileSystem fs = null;

    try {

      fs = FileSystems.newFileSystem(fileUri, Collections.<String, Object>emptyMap());

    } catch (FileSystemAlreadyExistsException e) {
      fs = FileSystems.getFileSystem(fileUri);
    }

    return fs.getPath(entryName);
  }
项目:jdk7-dxfs    文件:DxFileSystemProvider.java   
@Override
public final FileSystem newFileSystem(URI uri, Map<String,?> env) {

    final String defContextId = getContextIdByMap(env,defaultContextId);
    final PathTokens tokens = resolveUri(uri, defContextId);
    final String dxContextId = tokens.contextId;
    final DxFileSystem result = newFileSystem(dxContextId, tokens.name);

    if( fileSystems.putIfAbsent(dxContextId, result) != null ) {
        throw new FileSystemAlreadyExistsException();
    }

    return result;
}
项目:mycore    文件:MCRFileSystemProvider.java   
@Override
public FileSystem newFileSystem(URI uri, Map<String, ?> env) throws IOException {
    throw new FileSystemAlreadyExistsException();
}
项目:raml-module-builder    文件:Rules.java   
private ArrayList<String> getRules(URI uri) throws Exception {

    System.out.println("Getting rules from " + uri.toString());
    Path rulePath = null;
    ArrayList<String> list = new ArrayList<>();
    FileSystem fileSystem = null;

    if (uri.getScheme().equals("jar")) {
      try {
        //comment out sonar as this is closed at the end of the function
        fileSystem = FileSystems.newFileSystem(uri, Collections.<String, Object> emptyMap()); //NOSONAR
      } catch (FileSystemAlreadyExistsException e) {
        fileSystem = FileSystems.getFileSystem(uri);
      }
      rulePath = fileSystem.getPath(RULES_DIR_JAR);
    }
    else if(uri.isAbsolute()){
      rulePath = Paths.get(uri);
    }
    else {
      uri = Rules.class.getClassLoader().getResource(RULES_DIR_IDE).toURI();
      rulePath = Paths.get(uri);
    }
    Stream<Path> walk = Files.walk(rulePath, 1);
    for (Iterator<Path> it = walk.iterator(); it.hasNext();) {
      Path file = it.next();
      String name = file.getFileName().toString();
      if(name.endsWith("drl")){
        if (uri.getScheme().equals("jar")) {
          list.add(name);
        }else{
          list.add(file.toAbsolutePath().toString());
        }
      }
    }
    walk.close();
    if (fileSystem != null) {
      fileSystem.close();
    }
    return list;
  }
项目:encfs4j    文件:EncryptedFileSystemProvider.java   
@Override
public FileSystem newFileSystem(URI uri, Map<String, ?> env)
        throws IOException {
    assertUri(uri);
    synchronized (EncryptedFileSystemProvider.class) {
        if (encFileSystem != null)
            throw new FileSystemAlreadyExistsException();

        // check environment
        try {
            String cipherAlgorithm = (String) env.get(CIPHER_ALGORITHM);
            if (cipherAlgorithm == null)
                throw new IllegalArgumentException(
                        "Missing filesystem variable '" + CIPHER_ALGORITHM
                                + "'");

            String cipherAlgorithmMode = (String) env
                    .get(CIPHER_ALGORITHM_MODE);
            if (cipherAlgorithmMode == null)
                throw new IllegalArgumentException(
                        "Missing filesystem variable '"
                                + CIPHER_ALGORITHM_MODE + "'");

            String cipherAlgorithmPadding = (String) env
                    .get(CIPHER_ALGORITHM_PADDING);
            if (cipherAlgorithmPadding == null)
                throw new IllegalArgumentException(
                        "Missing filesystem variable '"
                                + CIPHER_ALGORITHM_PADDING + "'");

            cipherTransformation = cipherAlgorithm + "/"
                    + cipherAlgorithmMode + "/" + cipherAlgorithmPadding;
            Cipher.getInstance(cipherTransformation);
            // FSTODO: cipher.getParameters().getProvider() --> check secret
            // key length ?

            byte[] secretKey = (byte[]) env.get(SECRET_KEY);
            if (secretKey == null)
                throw new IllegalArgumentException(
                        "Missing filesystem variable '" + SECRET_KEY + "'");

            secretKeySpec = new SecretKeySpec(secretKey, cipherAlgorithm);

            String fileSystemRootString = (String) env
                    .get(FILESYSTEM_ROOT_URI);
            if (fileSystemRootString == null)
                fileSystemRootString = "file:/";
            fileSystemRoot = Paths.get(new URI(fileSystemRootString))
                    .normalize();

            String isReverseString = (String) env.get(REVERSE_MODE);
            isReverse = "true".equalsIgnoreCase(isReverseString);

        } catch (Exception e) {
            throw new IOException(e);
        }

        EncryptedFileSystem result = new EncryptedFileSystem(this,
                FileSystems.getDefault());
        encFileSystem = result;
        return result;
    }
}
项目:ephemeralfs    文件:EphemeralFsProviderTest.java   
@Test(expected=FileSystemAlreadyExistsException.class)
public void testCreateTwiceSameURIFails() throws Exception { 
    createTestFs();
    createTestFs();
}
项目:eightyfs    文件:ProviderURIStuff.java   
public FileSystem newFileSystem( EightyProvider eightyProvider, URI uri, Map<String, ?> env2 ) {

        checkURI( uri );

        Map<String, Object> env = (Map) env2;

        String id = uriMapper.getSchemeSpecificPart( uri );

        if( fileSystems.containsKey( id ) && fileSystems.get( id ).isOpen() ) {
            throw new FileSystemAlreadyExistsException( id );
        }

        Object fsid = uriMapper.fromString( id, env );

        RWAttributesBuilder attributesBuilder = RWAttributesBuilder.attributes();
        EightyFS efs = creator.create( fsid, attributesBuilder, env );

        EightyFileSystem eightyFileSystem = new EightyFileSystem( efs, id, eightyProvider, attributesBuilder.build() );
        fileSystems.put( id, eightyFileSystem );

        efs.setWatcher( eightyFileSystem );

        return eightyFileSystem;
    }
项目:encfs4j    文件:EncryptedFileSystemProvider.java   
@Override
public FileSystem newFileSystem(URI uri, Map<String, ?> env)
        throws IOException {
    assertUri(uri);
    synchronized (EncryptedFileSystemProvider.class) {
        if (encFileSystem != null)
            throw new FileSystemAlreadyExistsException();

        // check environment
        try {
            String cipherAlgorithm = (String) env.get(CIPHER_ALGORITHM);
            if (cipherAlgorithm == null)
                throw new IllegalArgumentException(
                        "Missing filesystem variable '" + CIPHER_ALGORITHM
                                + "'");

            String cipherAlgorithmMode = (String) env
                    .get(CIPHER_ALGORITHM_MODE);
            if (cipherAlgorithmMode == null)
                throw new IllegalArgumentException(
                        "Missing filesystem variable '"
                                + CIPHER_ALGORITHM_MODE + "'");

            String cipherAlgorithmPadding = (String) env
                    .get(CIPHER_ALGORITHM_PADDING);
            if (cipherAlgorithmPadding == null)
                throw new IllegalArgumentException(
                        "Missing filesystem variable '"
                                + CIPHER_ALGORITHM_PADDING + "'");

            cipherTransformation = cipherAlgorithm + "/"
                    + cipherAlgorithmMode + "/" + cipherAlgorithmPadding;
            Cipher.getInstance(cipherTransformation);
            // FSTODO: cipher.getParameters().getProvider() --> check secret
            // key length ?

            byte[] secretKey = (byte[]) env.get(SECRET_KEY);
            if (secretKey == null)
                throw new IllegalArgumentException(
                        "Missing filesystem variable '" + SECRET_KEY + "'");

            secretKeySpec = new SecretKeySpec(secretKey, cipherAlgorithm);

            String fileSystemRootString = (String) env
                    .get(FILESYSTEM_ROOT_URI);
            if (fileSystemRootString == null)
                fileSystemRootString = "file:/";
            fileSystemRoot = Paths.get(new URI(fileSystemRootString))
                    .normalize();

            String isReverseString = (String) env.get(REVERSE_MODE);
            isReverse = "true".equalsIgnoreCase(isReverseString);

        } catch (Exception e) {
            throw new IOException(e);
        }

        EncryptedFileSystem result = new EncryptedFileSystem(this,
                FileSystems.getDefault());
        encFileSystem = result;
        return result;
    }
}
项目:niotest    文件:Tests05URI.java   
@Test
public void testNewFileSystemOfExistingThrows() throws IOException {
    assertThatThrownBy( () -> FS.provider().newFileSystem( toURI( FS ), getEnv() ) ).
            isInstanceOf( FileSystemAlreadyExistsException.class );
}