Example usage for java.nio.file FileVisitResult CONTINUE

List of usage examples for java.nio.file FileVisitResult CONTINUE

Introduction

In this page you can find the example usage for java.nio.file FileVisitResult CONTINUE.

Prototype

FileVisitResult CONTINUE

To view the source code for java.nio.file FileVisitResult CONTINUE.

Click Source Link

Document

Continue.

Usage

From source file:se.trixon.mapollage.FileVisitor.java

@Override
public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) {
    if (mExcludePatterns != null) {
        for (String excludePattern : mExcludePatterns) {
            if (IOCase.SYSTEM.isCaseSensitive()) {
                if (StringUtils.contains(dir.toString(), excludePattern)) {
                    return FileVisitResult.SKIP_SUBTREE;
                }/*from  w  w w .  j  av a2 s . c om*/
            } else {
                if (StringUtils.containsIgnoreCase(dir.toString(), excludePattern)) {
                    return FileVisitResult.SKIP_SUBTREE;
                }
            }
        }
    }

    String[] filePaths = dir.toFile().list();

    mOperationListener.onOperationLog(dir.toString());
    mOperationListener.onOperationProgress(dir.toString());

    if (filePaths != null && filePaths.length > 0) {
        if (mUseExternalDescription) {
            Properties p = new Properties(mDefaultDescProperties);

            try {
                File file = new File(dir.toFile(), mExternalFileValue);
                if (file.isFile()) {
                    p.load(new InputStreamReader(new FileInputStream(file), Charset.defaultCharset()));
                }
            } catch (IOException ex) {
                // nvm
            }

            mDirToDesc.put(dir.toFile().getAbsolutePath(), p);
        }

        for (String fileName : filePaths) {
            try {
                TimeUnit.NANOSECONDS.sleep(1);
            } catch (InterruptedException ex) {
                mInterrupted = true;
                return FileVisitResult.TERMINATE;
            }
            File file = new File(dir.toFile(), fileName);
            if (file.isFile() && mPathMatcher.matches(file.toPath().getFileName())) {
                boolean exclude = false;
                if (mExcludePatterns != null) {
                    for (String excludePattern : mExcludePatterns) {
                        if (StringUtils.contains(file.getAbsolutePath(), excludePattern)) {
                            exclude = true;
                            break;
                        }
                    }
                }

                if (!exclude) {
                    mFiles.add(file);
                }
            }
        }
    }

    return FileVisitResult.CONTINUE;
}

From source file:com.amazonaws.codepipeline.jenkinsplugin.CompressionTools.java

public static List<File> addFilesToCompress(final Path pathToCompress, final BuildListener listener)
        throws IOException {
    final List<File> files = new ArrayList<>();

    if (pathToCompress != null) {
        Files.walkFileTree(pathToCompress, EnumSet.of(FileVisitOption.FOLLOW_LINKS), Integer.MAX_VALUE,
                new SimpleFileVisitor<Path>() {
                    @Override//from w ww.j av  a 2 s  .  c  o  m
                    public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs)
                            throws IOException {
                        files.add(file.toFile());
                        return FileVisitResult.CONTINUE;
                    }

                    @Override
                    public FileVisitResult visitFileFailed(final Path file, final IOException e)
                            throws IOException {
                        if (e != null) {
                            LoggingHelper.log(listener, "Failed to visit file '%s'. Error: %s.",
                                    file.toString(), e.getMessage());
                            LoggingHelper.log(listener, e);
                            throw e;
                        }
                        return FileVisitResult.CONTINUE;
                    }
                });
    }

    return files;
}

From source file:junit.org.rapidpm.microdao.HsqlDBBaseTestUtils.java

private boolean deleteDirectory(final String path) {
    final File indexDirectory = new File(path);
    if (indexDirectory.exists()) {
        try {/*  w w w .j  av  a 2 s .  c o  m*/
            Files.walkFileTree(indexDirectory.toPath(), new SimpleFileVisitor<Path>() {
                @Override
                public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs)
                        throws IOException {
                    Files.delete(file);
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult postVisitDirectory(final Path dir, final IOException exc)
                        throws IOException {
                    Files.delete(dir);
                    return FileVisitResult.CONTINUE;
                }
            });
        } catch (IOException e) {
            e.printStackTrace();
            return false;
        }
        return true;
    }
    return false;
}

From source file:se.trixon.mapollage.FileVisitor.java

@Override
public FileVisitResult visitFileFailed(Path file, IOException exception) {
    mOperation.logError(String.format("E000 %s", file.toString()));

    return FileVisitResult.CONTINUE;
}

From source file:uk.co.unclealex.executable.impl.MakeLinksCommandRunnerTest.java

protected Path copy(String testCase, String directoryName) throws IOException {
    Path sourceDir = rootDir.resolve(testCase).resolve(directoryName);
    Path target = tmpDir.resolve(directoryName);
    Files.createDirectories(target);
    if (Files.exists(sourceDir)) {
        FileUtils.copyDirectory(sourceDir.toFile(), target.toFile());
        FileVisitor<Path> visitor = new SimpleFileVisitor<Path>() {
            @Override//w w  w.  j  a v  a2 s .  c  om
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                String name = file.getFileName().toString();
                for (Entry<String, Path> entry : symlinksByName.entrySet()) {
                    String suffix = entry.getKey();
                    Path symlink = entry.getValue();
                    if (name.endsWith(suffix)) {
                        Files.delete(file);
                        String newName = name.substring(0, name.length() - suffix.length());
                        Files.createSymbolicLink(file.resolveSibling(newName), symlink);
                        return FileVisitResult.CONTINUE;
                    }
                }
                return FileVisitResult.CONTINUE;
            }
        };
        Files.walkFileTree(target, visitor);
    }
    return target;
}

From source file:edu.mit.lib.handbag.Controller.java

public void initialize() {

    Image wfIm = new Image(getClass().getResourceAsStream("/SiteMap.png"));
    workflowLabel.setGraphic(new ImageView(wfIm));
    workflowLabel.setContentDisplay(ContentDisplay.BOTTOM);

    workflowChoiceBox.addEventHandler(ActionEvent.ACTION, event -> {
        if (workflowChoiceBox.getItems().size() != 0) {
            return;
        }//from  w  ww.  ja v  a2  s. c om
        ObservableList<Workflow> wflowList = FXCollections.observableArrayList(loadWorkflows());
        workflowChoiceBox.setItems(wflowList);
        workflowChoiceBox.getSelectionModel().selectedIndexProperty().addListener((ov, value, new_value) -> {
            int newVal = (int) new_value;
            if (newVal != -1) {
                Workflow newSel = workflowChoiceBox.getItems().get(newVal);
                if (newSel != null) {
                    workflowLabel.setText(newSel.getName());
                    generateBagName(newSel.getBagNameGenerator());
                    bagLabel.setText(bagName);
                    sendButton.setText(newSel.getDestinationName());
                    setMetadataList(newSel);
                }
            }
        });
    });

    Image bagIm = new Image(getClass().getResourceAsStream("/Bag.png"));
    bagLabel.setGraphic(new ImageView(bagIm));
    bagLabel.setContentDisplay(ContentDisplay.BOTTOM);

    Image sendIm = new Image(getClass().getResourceAsStream("/Cabinet.png"));
    sendButton.setGraphic(new ImageView(sendIm));
    sendButton.setContentDisplay(ContentDisplay.BOTTOM);
    sendButton.setDisable(true);
    sendButton.setOnAction(e -> transmitBag());

    Image trashIm = new Image(getClass().getResourceAsStream("/Bin.png"));
    trashButton.setGraphic(new ImageView(trashIm));
    trashButton.setContentDisplay(ContentDisplay.BOTTOM);
    trashButton.setDisable(true);
    trashButton.setOnAction(e -> reset(false));

    TreeItem<PathRef> rootItem = new TreeItem<>(new PathRef("", Paths.get("data")));
    rootItem.setExpanded(true);
    payloadTreeView.setRoot(rootItem);
    payloadTreeView.setOnDragOver(event -> {
        if (event.getGestureSource() != payloadTreeView && event.getDragboard().getFiles().size() > 0) {
            event.acceptTransferModes(TransferMode.COPY_OR_MOVE);
        }
        event.consume();
    });
    payloadTreeView.setOnDragDropped(event -> {
        Dragboard db = event.getDragboard();
        boolean success = false;
        if (db.getFiles().size() > 0) {
            for (File dragFile : db.getFiles()) {
                if (dragFile.isDirectory()) {
                    // explode directory and add expanded relative paths to tree
                    relPathSB = new StringBuilder();
                    try {
                        Files.walkFileTree(dragFile.toPath(), new SimpleFileVisitor<Path>() {
                            @Override
                            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs)
                                    throws IOException {
                                relPathSB.append(dir.getFileName()).append("/");
                                return FileVisitResult.CONTINUE;
                            }

                            @Override
                            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
                                    throws IOException {
                                payloadTreeView.getRoot().getChildren()
                                        .add(new TreeItem<>(new PathRef(relPathSB.toString(), file)));
                                bagSize += Files.size(file);
                                return FileVisitResult.CONTINUE;
                            }
                        });
                    } catch (IOException ioe) {
                    }
                } else {
                    payloadTreeView.getRoot().getChildren()
                            .add(new TreeItem<>(new PathRef("", dragFile.toPath())));
                    bagSize += dragFile.length();
                }
            }
            bagSizeLabel.setText(scaledSize(bagSize, 0));
            success = true;
            updateButtons();
        }
        event.setDropCompleted(success);
        event.consume();
    });

    metadataPropertySheet.setModeSwitcherVisible(false);
    metadataPropertySheet.setDisable(false);
    metadataPropertySheet.addEventHandler(KeyEvent.ANY, event -> {
        checkComplete(metadataPropertySheet.getItems());
        event.consume();
    });
}

From source file:org.eclipse.vorto.remoterepository.internal.dao.FilesystemModelDAO.java

private void walkDirectoryTree(final ModelFoundHandler handler) {
    try {//from   w  w w.j a  va  2  s.co m
        Files.walkFileTree(Paths.get(getRepositoryBaseDirectory()), new SimpleFileVisitor<Path>() {
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                handler.handle(file);
                return FileVisitResult.CONTINUE;
            }
        });
    } catch (IOException e) {
        throw new RuntimeException("An I/O error was thrown", e);
    }
}

From source file:com.marklogic.hub.RestAssetLoader.java

@Override
public FileVisitResult postVisitDirectory(Path path, IOException exception) throws IOException {
    return FileVisitResult.CONTINUE;
}

From source file:gov.vha.isaac.rf2.filter.RF2Filter.java

@Override
public void execute() throws MojoExecutionException {
    if (!inputDirectory.exists() || !inputDirectory.isDirectory()) {
        throw new MojoExecutionException("Path doesn't exist or isn't a folder: " + inputDirectory);
    }// www . java  2  s  .co  m

    if (module == null) {
        throw new MojoExecutionException("You must provide a module or namespace for filtering");
    }

    moduleStrings_.add(module + "");

    outputDirectory.mkdirs();
    File temp = new File(outputDirectory, inputDirectory.getName());
    temp.mkdirs();

    Path source = inputDirectory.toPath();
    Path target = temp.toPath();
    try {
        getLog().info("Reading from " + inputDirectory.getAbsolutePath());
        getLog().info("Writing to " + outputDirectory.getCanonicalPath());

        summary_.append("This content was filtered by an RF2 filter tool.  The parameters were module: "
                + module + " software version: " + converterVersion);
        summary_.append("\r\n\r\n");

        getLog().info("Checking for nested child modules");

        //look in sct2_Relationship_ files, find anything where the 6th column (destinationId) is the 
        //starting module ID concept - and add that sourceId (5th column) to our list of modules to extract
        Files.walkFileTree(source, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                if (file.toFile().getName().startsWith("sct2_Relationship_")) {
                    //don't look for quotes, the data is bad, and has floating instances of '"' all by itself
                    CSVReader csvReader = new CSVReader(
                            new InputStreamReader(new FileInputStream(file.toFile())), '\t',
                            CSVParser.NULL_CHARACTER);
                    String[] line = csvReader.readNext();
                    if (!line[4].equals("sourceId") || !line[5].equals("destinationId")) {
                        csvReader.close();
                        throw new IOException("Unexpected error looking for nested modules");
                    }
                    line = csvReader.readNext();
                    while (line != null) {
                        if (line[5].equals(moduleStrings_.get(0))) {
                            moduleStrings_.add(line[4]);
                        }
                        line = csvReader.readNext();
                    }
                    csvReader.close();
                }
                return FileVisitResult.CONTINUE;
            }
        });

        log("Full module list (including detected nested modules: "
                + Arrays.toString(moduleStrings_.toArray(new String[moduleStrings_.size()])));

        Files.walkFileTree(source, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
                Path targetdir = target.resolve(source.relativize(dir));
                try {
                    //this just creates the sub-directory in the target
                    Files.copy(dir, targetdir);
                } catch (FileAlreadyExistsException e) {
                    if (!Files.isDirectory(targetdir))
                        throw e;
                }
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                handleFile(file, target.resolve(source.relativize(file)));
                return FileVisitResult.CONTINUE;
            }
        });

        Files.write(new File(temp, "FilterInfo.txt").toPath(), summary_.toString().getBytes(),
                StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING);
    } catch (IOException e) {
        throw new MojoExecutionException("Failure", e);
    }

    getLog().info("Filter Complete");

}

From source file:com.bekwam.resignator.commands.UnsignCommand.java

private void registerCleanup() {
    Runtime.getRuntime().addShutdownHook(new Thread() {
        @Override//from   w  ww  .  j  a  va  2s . c o m
        public void run() {
            if (logger.isDebugEnabled()) {
                logger.debug("[UNSIGN] shutting down unsign jar command");
            }
            if (tempDir != null) {
                if (logger.isDebugEnabled()) {
                    logger.debug("[UNSIGN] tempDir is not null");
                }
                try {
                    Files.walkFileTree(tempDir, new SimpleFileVisitor<Path>() {
                        @Override
                        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs)
                                throws IOException {
                            if (logger.isDebugEnabled()) {
                                logger.debug("[UNSIGN] deleting file={}", file.getFileName());
                            }
                            Files.delete(file);
                            return FileVisitResult.CONTINUE;
                        }

                        @Override
                        public FileVisitResult postVisitDirectory(Path dir, IOException exc)
                                throws IOException {
                            if (exc == null) {
                                if (logger.isDebugEnabled()) {
                                    logger.debug("[UNSIGN] deleting dir={}", dir.getFileName());
                                }
                                Files.delete(dir);
                                return FileVisitResult.CONTINUE;
                            } else {
                                // directory iteration failed
                                throw exc;
                            }
                        }
                    });
                } catch (Exception exc) {
                    logger.error("error removing tempDir=" + tempDir, exc);
                }
            }
        }
    });
}