Package java.nio.file

Examples of java.nio.file.FileSystem


        return new File(test).toPath();
    }

    public static PathMatcher getMatcher(final String rawpattern)
    {
        FileSystem fs = FileSystems.getDefault();
       
        String pattern = rawpattern;
       
        // Strip trailing slash (if present)
        int lastchar = pattern.charAt(pattern.length() - 1);
        if (lastchar == '/' || lastchar == '\\')
        {
            pattern = pattern.substring(0,pattern.length() - 1);
        }

        // If using FileSystem.getPathMatcher() with "glob:" or "regex:"
        // use FileSystem default pattern behavior
        if (pattern.startsWith("glob:") || pattern.startsWith("regex:"))
        {
            StartLog.debug("Using Standard " + fs.getClass().getName() + " pattern: " + pattern);
            return fs.getPathMatcher(pattern);
        }

        // If the pattern starts with a root path then its assumed to
        // be a full system path
        if (isAbsolute(pattern))
        {
            String pat = "glob:" + pattern;
            StartLog.debug("Using absolute path pattern: " + pat);
            return fs.getPathMatcher(pat);
        }

        // Doesn't start with filesystem root, then assume the pattern
        // is a relative file path pattern.
        String pat = "glob:**/" + pattern;
        StartLog.debug("Using relative path pattern: " + pat);
        return fs.getPathMatcher(pat);
    }
View Full Code Here


     * Returns true if any of the files appear to be stored in NFS (or we
     * can't tell).
     */
    private boolean mightUseNFS(File... files) {
        try {
            FileSystem fileSystem = FileSystems.getDefault();
            for (File file: files) {
                Path path = fileSystem.getPath(file.getAbsolutePath());
                String fileStoreType = Files.getFileStore(path).type();
                if (fileStoreType.toLowerCase().contains("nfs")) {
                    return true;
                }
            }
View Full Code Here

    public static void initialize() {
        getEnvVars();
        // set the standard vars defined by R
        String rHome = rHome();
        FileSystem fileSystem = FileSystems.getDefault();
        envVars.put("R_DOC_DIR", fileSystem.getPath(rHome, "doc").toString());
        envVars.put("R_INCLUDE_DIR", fileSystem.getPath(rHome, "include").toString());
        envVars.put("R_SHARE_DIR", fileSystem.getPath(rHome, "share").toString());

        if (!RCmdOptions.NO_ENVIRON.getValue()) {
            String siteFile = envVars.get("R_ENVIRON");
            if (siteFile == null) {
                siteFile = fileSystem.getPath(rHome, "etc", "Renviron.site").toString();
            }
            if (new File(siteFile).exists()) {
                safeReadEnvironFile(siteFile);
            }
            String userFile = envVars.get("R_ENVIRON_USER");
            if (userFile == null) {
                String dotRenviron = ".Renviron";
                userFile = fileSystem.getPath(RFFIFactory.getRFFI().getBaseRFFI().getwd(), dotRenviron).toString();
                if (!new File(userFile).exists()) {
                    userFile = fileSystem.getPath(System.getProperty("user.home"), dotRenviron).toString();
                }
            }
            if (userFile != null && new File(userFile).exists()) {
                safeReadEnvironFile(userFile);
            }
View Full Code Here

            }
            if (lenTo < 1) {
                return RDataFactory.createLogicalVector(0);
            }
            int len = lenFrom > lenTo ? lenFrom : lenTo;
            FileSystem fileSystem = FileSystems.getDefault();
            byte[] status = new byte[len];
            for (int i = 0; i < len; i++) {
                String from = vecFrom.getDataAt(i % lenFrom);
                String to = vecTo.getDataAt(i % lenTo);
                if (RRuntime.isNA(from) || RRuntime.isNA(to)) {
                    status[i] = RRuntime.LOGICAL_FALSE;
                } else {
                    Path fromPath = fileSystem.getPath(Utils.tildeExpand(from));
                    Path toPath = fileSystem.getPath(Utils.tildeExpand(to));
                    status[i] = RRuntime.LOGICAL_TRUE;
                    try {
                        if (symbolic) {
                            Files.createSymbolicLink(toPath, fromPath);
                        } else {
View Full Code Here

        public abstract static class PathFunction {
            protected abstract String invoke(FileSystem fileSystem, String name);
        }

        protected RStringVector doXyzName(RAbstractStringVector vec, PathFunction fun) {
            FileSystem fileSystem = FileSystems.getDefault();
            boolean complete = RDataFactory.COMPLETE_VECTOR;
            String[] data = new String[vec.getLength()];
            for (int i = 0; i < data.length; i++) {
                String name = vec.getDataAt(i);
                if (RRuntime.isNA(name)) {
View Full Code Here

    @Specialization
    protected RStringVector doNormalizePath(RAbstractStringVector pathVec, @SuppressWarnings("unused") String winslash, byte mustWork) {
        controlVisibility();
        String[] results = new String[pathVec.getLength()];
        FileSystem fileSystem = FileSystems.getDefault();
        for (int i = 0; i < results.length; i++) {
            String path = pathVec.getDataAt(i);
            String expandPath = Utils.tildeExpand(path);
            String normPath = expandPath;
            try {
                normPath = fileSystem.getPath(path).toRealPath().toString();
            } catch (IOException e) {
                if (doesNotNeedToWork.profile(mustWork == RRuntime.LOGICAL_FALSE)) {
                    // no error or warning
                } else {
                    Object[] errorArgs;
View Full Code Here

  private static final Logger logger = LoggerFactory.getLogger(StaticFilesDevConfig.class);

  @Override
  public void addResourceHandlers(ResourceHandlerRegistry registry) {
    try {
      FileSystem fs = FileSystems.getDefault();
      registry.addResourceHandler("/**")
          .addResourceLocations("file:" + fs.getPath(this.relativePath).toFile().getCanonicalPath() + "/")
          .setCachePeriod(0);
    } catch (IOException e) {
      logger.error("Error while adding static files handler", e);
    }
  }
View Full Code Here

    return PathMatchers.getPathMatcher("glob:" + pattern, "/", ImmutableSet.<PathNormalization>of());
  }

  @Override
  protected PathMatcher realMatcher(String pattern) {
    FileSystem defaultFileSystem = FileSystems.getDefault();
    if ("/".equals(defaultFileSystem.getSeparator())) {
      return defaultFileSystem.getPathMatcher("glob:" + pattern);
    }
    return null;
  }
View Full Code Here

    tester.assertModifiedTimeDidNotChange();
  }

  @Test
  public void testUnsupportedFeatures() throws IOException {
    FileSystem fileSystem = Jimfs.newFileSystem(Configuration.unix().toBuilder()
        .setSupportedFeatures() // none
        .build());

    Path foo = fileSystem.getPath("foo");
    Path bar = foo.resolveSibling("bar");

    try {
      Files.createLink(foo, bar);
      fail();
View Full Code Here

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

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

    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"));
    Files.createFile(fs.getPath("/FOO"));
  }
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.