Example usage for java.nio.file Path getFileSystem

List of usage examples for java.nio.file Path getFileSystem

Introduction

In this page you can find the example usage for java.nio.file Path getFileSystem.

Prototype

FileSystem getFileSystem();

Source Link

Document

Returns the file system that created this object.

Usage

From source file:Main.java

public static void main(String[] args) {
    Path path = Paths.get("C:/home/./music/users.txt");

    System.out.println(path.getFileSystem().getSeparator());

}

From source file:Test.java

  public static void main(String[] args) {
  Path path = Paths.get("C:/home/docs/users.txt");
  FileSystem fileSystem = path.getFileSystem();
  Set<String> supportedViews = fileSystem.supportedFileAttributeViews();

  for (String view : supportedViews) {
    System.out.println(view);//w ww .j  a  v a  2  s. c om
  }
}

From source file:Main.java

public static void main(String[] args) {
    Path path = Paths.get("C:/home/docs/users.txt");
    FileSystem fileSystem = path.getFileSystem();
    Set<String> supportedViews = fileSystem.supportedFileAttributeViews();

    for (String view : supportedViews) {
        System.out.println(view);
    }/* w  ww  . j  a va2  s .  c om*/
}

From source file:com.ilscipio.scipio.common.FileListener.java

/**
 *  Start a file listener (WatchService) and run a service of a given name and writes the result to the database
 *  Can be used to implements EECAs to auto-update information based on file changes
 **/// w  w  w. jav a 2s . c  om
public static void startFileListener(String name, String location) {

    try {
        if (UtilValidate.isNotEmpty(name) && UtilValidate.isNotEmpty(location)) {

            if (getThreadByName(name) != null) {
                Debug.logInfo("Filelistener " + name + " already started. Skipping...", module);
            } else {
                URL resLocation = UtilURL.fromResource(location);
                Path folderLocation = Paths.get(resLocation.toURI());
                if (folderLocation == null) {
                    throw new UnsupportedOperationException("Directory not found");
                }

                final WatchService folderWatcher = folderLocation.getFileSystem().newWatchService();
                // register all subfolders
                Files.walkFileTree(folderLocation, new SimpleFileVisitor<Path>() {
                    @Override
                    public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
                            throws IOException {
                        dir.register(folderWatcher, StandardWatchEventKinds.ENTRY_CREATE,
                                StandardWatchEventKinds.ENTRY_DELETE, StandardWatchEventKinds.ENTRY_MODIFY);
                        return FileVisitResult.CONTINUE;
                    }
                });

                // start the file watcher thread below
                ScipioWatchQueueReader fileListener = new ScipioWatchQueueReader(folderWatcher, name, location);
                ScheduledExecutorService executor = ExecutionPool.getScheduledExecutor(
                        FILE_LISTENER_THREAD_GROUP, "filelistener-startup",
                        Runtime.getRuntime().availableProcessors(), 0, true);
                try {
                    executor.submit(fileListener, name);
                } finally {
                    executor.shutdown();
                }
                Debug.logInfo("Starting FileListener thread for " + name, module);
            }
        }
    } catch (Exception e) {
        Debug.logError("Could not start FileListener " + name + " for " + location + "\n" + e, module);

    }
}

From source file:com.facebook.buck.zip.Unzip.java

public static ImmutableList<Path> extractZipFile(Path zipFile, final Path destination,
        ExistingFileMode existingFileMode) throws IOException {
    // Create output directory if it does not exist
    Files.createDirectories(destination);
    return extractZipFile(zipFile, new ProjectFilesystem(destination), destination.getFileSystem().getPath(""),
            existingFileMode).stream().map(input -> destination.resolve(input).toAbsolutePath())
                    .collect(MoreCollectors.toImmutableList());
}

From source file:com.netflix.genie.agent.cli.UserConsole.java

/**
 * Move the log file from the current position to the given destination.
 * Refuses to move across filesystems. Moving within the same filesystem should not invalidate any open descriptors.
 *
 * @param destinationPath destination path
 * @throws IOException if source and destination are on different filesystem devices, if destination exists, or if
 *                     the move fails./*from  ww w .ja  v a2 s . c  om*/
 */
public static synchronized void relocateLogFile(final Path destinationPath) throws IOException {

    final Path sourcePath = CURRENT_LOG_FILE_PATH.get();
    final Path destinationAbsolutePath = destinationPath.toAbsolutePath();

    if (!Files.exists(sourcePath)) {
        throw new IOException("Log file does not exists: " + sourcePath.toString());
    } else if (Files.exists(destinationAbsolutePath)) {
        throw new IOException("Destination already exists: " + destinationAbsolutePath.toString());
    } else if (!sourcePath.getFileSystem().provider()
            .equals(destinationAbsolutePath.getFileSystem().provider())) {
        throw new IOException("Source and destination are not in the same filesystem");
    }

    Files.move(sourcePath, destinationAbsolutePath);
    CURRENT_LOG_FILE_PATH.set(destinationAbsolutePath);

    getLogger().info("Agent log file relocated to: " + getLogFilePath());
}

From source file:com.spotify.docker.client.CompressedDirectory.java

static ImmutableSet<PathMatcher> parseDockerIgnore(Path dockerIgnorePath) throws IOException {
    final ImmutableSet.Builder<PathMatcher> matchersBuilder = ImmutableSet.builder();

    if (Files.isReadable(dockerIgnorePath) && Files.isRegularFile(dockerIgnorePath)) {
        for (final String line : Files.readAllLines(dockerIgnorePath, StandardCharsets.UTF_8)) {
            final String pattern = line.trim();
            if (pattern.isEmpty()) {
                log.debug("Will skip '{}' - cause it's empty after trimming", line);
                continue;
            }/*from w w  w  . j  a va2s  .  c  om*/
            matchersBuilder.add(goPathMatcher(dockerIgnorePath.getFileSystem(), pattern));
        }
    }

    return matchersBuilder.build();
}

From source file:cn.edu.zjnu.acm.judge.controller.CKFinderController.java

@Nullable
@ToDownload//from   w w  w . j av  a  2 s .  c  o  m
@GetMapping("/support/ckfinder")
public Path ckfinder(@RequestParam("path") String path) {
    log.info(path);
    try {
        int indexOf = path.indexOf('?');
        Path parent = judgeConfiguration.getUploadDirectory();
        Path imagePath = parent.getFileSystem()
                .getPath(parent.toString(), indexOf > 0 ? path.substring(0, indexOf) : path).normalize();
        if (!imagePath.startsWith(parent)) {
            log.debug("absolute path parent='{}' path='{}'", parent, imagePath);
            return null;
        }
        return imagePath;
    } catch (IllegalArgumentException ex) {
        return null;
    }
}

From source file:com.github.zhanhb.ckfinder.connector.handlers.command.BaseCommand.java

@SuppressWarnings("FinalMethod")
protected final Path getPath(Path first, String... more) {
    return first.getFileSystem().getPath(first.toString(), more);
}

From source file:net.mindengine.dashserver.compiler.GlobalAssetsFileWatcher.java

@Override
public void run() {
    copyAllAssets();/*from  w  ww  .ja v a  2s  .  c  o  m*/

    Path path = Paths.get(this.assetsFolderPath);
    FileSystem fileSystem = path.getFileSystem();
    try (WatchService service = fileSystem.newWatchService()) {
        path.register(service, ENTRY_MODIFY, ENTRY_CREATE);

        while (true) {
            WatchKey watchKey = service.take();

            for (WatchEvent<?> watchEvent : watchKey.pollEvents()) {
                Path watchEventPath = (Path) watchEvent.context();
                String fileName = watchEventPath.toString();
                copyFileAsset(fileName);
            }

            if (!watchKey.reset()) {
                break;
            }
        }
    } catch (Exception e) {
        e.printStackTrace();
    }
}