Package java.nio.file

Examples of java.nio.file.FileSystem


* Date: 9/7/13
* Time: 10:14 PM
*/
public class InvertUtils {
  public Path getPath(String name) {
    FileSystem fs = FileSystems.getDefault();
    Path path = fs.getPath(name);
    if (path.toFile().exists()) {
      return path;
    } else {
      return fs.getPath("compiler/" + name);
    }
  }
View Full Code Here


public class FilesFilter {

  public List<Path> getFiles(String path, FileExtension fileExtension) {

    FileSystem fileSystem = FileSystems.getDefault();

    List<Path> files = new ArrayList<>() ;

    try(DirectoryStream<Path> directoryStream =
        Files.newDirectoryStream( fileSystem.getPath(path), "*" + fileExtension.getExtension())) {

      for (Path file : directoryStream) {
        files.add(file);
      }

View Full Code Here

      return new ArrayList<>(allJsInputs);
    }

    private void matchPaths(String pattern, final Set<String> allJsInputs)
        throws IOException {
      FileSystem fs = FileSystems.getDefault();
      final boolean remove = pattern.indexOf('!') == 0;
      if (remove) pattern = pattern.substring(1);

      if (File.separator.equals("\\")) {
        pattern = pattern.replace('\\', '/');
      }

      // Split the pattern into two pieces: the globbing part
      // and the non-globbing prefix.
      List<String> patternParts = Splitter.on('/').splitToList(pattern);
      String prefix = ".";
      for (int i = 0; i < patternParts.size(); i++) {
        if (patternParts.get(i).contains("*")) {
          if (i == 0) {
            break;
          } else {
            prefix = Joiner.on("/").join(patternParts.subList(0, i));
            pattern = Joiner.on("/").join(patternParts.subList(i, patternParts.size()));
          }
        }
      }

      final PathMatcher matcher = fs.getPathMatcher("glob:" + pattern);
      java.nio.file.Files.walkFileTree(
          fs.getPath(prefix), new SimpleFileVisitor<Path>() {
            @Override public FileVisitResult visitFile(
                Path p, BasicFileAttributes attrs) {
              if (matcher.matches(p)) {
                if (remove) {
                  allJsInputs.remove(p.toString());
View Full Code Here

      log.debug("Extracting application resource path: " + resourcePath);
      return resourcePath;
    } catch (final Throwable e) {
      if (e instanceof FileSystemNotFoundException) {
        // must be running from within a JAR- get the resource from within the archive
        FileSystem fs = null;
        try {
          final Path appPath = new File(applicationUri()).toPath();
          fs = FileSystems.newFileSystem(appPath, null);
          final Path resourcePath = fs.getPath(RS.class.getPackage().getName().replace(".", fs.getSeparator()), resourceName);
          if (resourcePath != null && validate && Files.notExists(resourcePath)) {
            return null;
          }
          log.debug(String.format("Extracting application resource from ZIP path %1$s in %2$s", resourcePath.toAbsolutePath(),
              appPath.toAbsolutePath()));
          return resourcePath;
        } catch (final Throwable e2) {
          log.error("Unable to get application path (ZIP source)", e2);
        } finally {
          if (closeFileSystem) {
            try {
              fs.close();
            } catch (final Exception e2) {
            }
          }
        }
      } else {
View Full Code Here

  /**
   * @param args
   */
  public static void main(String[] args) {
    FileSystem fileSystem = FileSystems.getDefault();
    for(Path rootDirectory: fileSystem.getRootDirectories()) {
      System.out.println(rootDirectory.getFileSystem());
      System.out.println(rootDirectory.toString());
    }
  }
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

  public static boolean renameFile(File from, File to) throws IOException {
    if (useOldFileAPI)
      return from.renameTo(to);

    final FileSystem fileSystem = FileSystems.getDefault();

    final Path fromPath = fileSystem.getPath(from.getAbsolutePath());
    final Path toPath = fileSystem.getPath(to.getAbsolutePath());
    Files.move(fromPath, toPath);

    return true;
  }
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.