Package java.nio.file

Examples of java.nio.file.FileSystem


    assertThat(config.defaultAttributeValues).isEmpty();
  }

  @Test
  public void testFileSystemForDefaultOsXConfiguration() throws IOException {
    FileSystem fs = Jimfs.newFileSystem(Configuration.osX());

    assertThat(fs.getRootDirectories())
        .containsExactlyElementsIn(ImmutableList.of(fs.getPath("/")))
        .inOrder();
    assertThatPath(fs.getPath("").toRealPath()).isEqualTo(fs.getPath("/work"));
    assertThat(Iterables.getOnlyElement(fs.getFileStores()).getTotalSpace()).isEqualTo(
        4L * 1024 * 1024 * 1024);
    assertThat(fs.supportedFileAttributeViews()).containsExactly("basic");

    Files.createFile(fs.getPath("/foo"));

    try {
      Files.createFile(fs.getPath("/FOO"));
      fail();
    } catch (FileAlreadyExistsException expected) {
    }
  }
View Full Code Here


    assertThat(config.defaultAttributeValues).isEmpty();
  }

  @Test
  public void testFileSystemForDefaultWindowsConfiguration() throws IOException {
    FileSystem fs = Jimfs.newFileSystem(Configuration.windows());

    assertThat(fs.getRootDirectories())
        .containsExactlyElementsIn(ImmutableList.of(fs.getPath("C:\\")))
        .inOrder();
    assertThatPath(fs.getPath("").toRealPath()).isEqualTo(fs.getPath("C:\\work"));
    assertThat(Iterables.getOnlyElement(fs.getFileStores()).getTotalSpace()).isEqualTo(
        4L * 1024 * 1024 * 1024);
    assertThat(fs.supportedFileAttributeViews()).containsExactly("basic");

    Files.createFile(fs.getPath("C:\\foo"));

    try {
      Files.createFile(fs.getPath("C:\\FOO"));
      fail();
    } catch (FileAlreadyExistsException expected) {
    }
  }
View Full Code Here

        .setAttributeViews("unix")
        .setDefaultAttributeValue(
            "posix:permissions", PosixFilePermissions.fromString("---------"))
        .build();

    FileSystem fs = Jimfs.newFileSystem(config);

    assertThat(fs.getRootDirectories())
        .containsExactlyElementsIn(ImmutableList.of(fs.getPath("/")))
        .inOrder();
    assertThatPath(fs.getPath("").toRealPath()).isEqualTo(fs.getPath("/hello/world"));
    assertThat(Iterables.getOnlyElement(fs.getFileStores()).getTotalSpace()).is(100);
    assertThat(fs.supportedFileAttributeViews()).containsExactly("basic", "owner", "posix", "unix");

    Files.createFile(fs.getPath("/foo"));
    assertThat(Files.getAttribute(fs.getPath("/foo"), "posix:permissions")).isEqualTo(
        PosixFilePermissions.fromString("---------"));

    try {
      Files.createFile(fs.getPath("/FOO"));
      fail();
    } catch (FileAlreadyExistsException expected) {
    }
  }
View Full Code Here

  protected String valueToString(Path value) throws PreferencesException
  {
    //Saving
   
    //If this is the local file system then just write the path in its string form
    FileSystem fs = value.getFileSystem();
    if (FileSystems.getDefault().equals(fs))
      return(value.toString());
   
    //Special file system handling
    String result = pathToStringForSpecialFileSystem(value);
View Full Code Here

     * @param aSessionHashCode A session hash code
     * @param aRemoteClient The remote endpoint
     * @throws IOException If there is a problem reading or writing
     */
    public LogWatcherThread(String aLogPath, int aSessionHashCode, RemoteEndpoint aRemoteClient) throws IOException {
        FileSystem fs = FileSystems.getDefault();
        Path logPath = fs.getPath(aLogPath);

        if (LOGGER.isInfoEnabled()) {
            LOGGER.info("[{}] Initializing new {} to monitor file system at {}", aSessionHashCode,
                    LogWatcherThread.class.getSimpleName(), aLogPath);
        }

        // Start the new watch service for our log files
        myWatchService = fs.newWatchService();
        myKeys = new ConcurrentHashMap<WatchKey, Path>();
        mySessionHashCode = aSessionHashCode;

        // Register the path of the log files with our watch service
        myKeys.put(logPath.register(myWatchService, ENTRY_CREATE, ENTRY_DELETE, ENTRY_MODIFY), logPath);
View Full Code Here

        final Path pathDir;
        if (isDirectory(path))
            pathDir = path;
        else {
            FileSystem fs = getFileSystem(path);
            if (fs == null)
                return;
            pathDir = fs.getRootDirectories().iterator().next();
        }
        String sep = path.getFileSystem().getSeparator();
        Path packageDir = packageName.isEmpty() ? pathDir
                : pathDir.resolve(packageName.replace(".", sep));
        if (!Files.exists(packageDir))
View Full Code Here

            if (isDirectory(p)) {
                Path f = resolve(p, relativePath);
                if (Files.exists(f))
                    return PathFileObject.createDirectoryPathFileObject(this, f, p);
            } else {
                FileSystem fs = getFileSystem(p);
                if (fs != null) {
                    Path file = getPath(fs, relativePath);
                    if (Files.exists(file))
                        return PathFileObject.createJarPathFileObject(this, file);
                }
View Full Code Here

        return ((PathFileObject) fo).inferBinaryName(paths);
    }

    private FileSystem getFileSystem(Path p) throws IOException {
        FileSystem fs = fileSystems.get(p);
        if (fs == null) {
            fs = FileSystems.newFileSystem(p, null);
            fileSystems.put(p, fs);
        }
        return fs;
View Full Code Here

    private static Path getPath(FileSystem fs, String relativePath) {
        return fs.getPath(relativePath.replace("/", fs.getSeparator()));
    }

    private static Path resolve(Path base, String relativePath) {
        FileSystem fs = base.getFileSystem();
        Path rp = fs.getPath(relativePath.replace("/", fs.getSeparator()));
        return base.resolve(rp);
    }
View Full Code Here

            return true;
        }

        @Override
        public List<Copy> getResources(Environment env) {
            FileSystem fs = FileSystems.getDefault();
            List<Copy> result = new ArrayList<>();
            result.add(substituting("source",
                    fs.getPathMatcher("glob:**"),
                    new Template("@[source.folder]/@[module.dir]").eval(env)));
           
            if ("true".equals(env.get("ant"))) {
                result.add(substituting("ant", "build.xml", "."));
            }
            if ("true".equals(env.get("eclipse"))) {
                result.add(substituting("eclipse",
                        fs.getPathMatcher("glob:**"),
                        "."));
            }
            return result;
        }
View Full Code Here

TOP

Related Classes of java.nio.file.FileSystem

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.