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:edu.cwru.jpdg.Javac.java

@Override
public FileVisitResult visitFileFailed(Path file, IOException exc) {
    return FileVisitResult.CONTINUE;
}

From source file:com.streamsets.datacollector.bundles.content.SdcInfoContentGenerator.java

private void listDirectory(String configDir, String name, BundleWriter writer) throws IOException {
    writer.markStartOfFile("dir_listing/" + name);
    Path prefix = Paths.get(configDir);

    try {/*  w  w  w.j  a  v  a 2 s  .  c om*/
        Files.walkFileTree(Paths.get(configDir), new FileVisitor<Path>() {
            @Override
            public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException {
                printFile(dir, prefix, DIR, writer);
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                printFile(file, prefix, FILE, writer);
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult visitFileFailed(Path file, IOException exc) throws IOException {
                return FileVisitResult.CONTINUE;
            }

            @Override
            public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
                return FileVisitResult.CONTINUE;
            }
        });
    } catch (Exception e) {
        LOG.error("Can't generate listing of {} directory: {}", configDir, e.toString(), e);
    }
    writer.markEndOfFile();
}

From source file:org.testeditor.fixture.swt.SwtBotFixture.java

/**
 * /*from  www.ja  va  2s .  c o m*/
 * @return utility FileVisitor class for recursive directory delete
 *         operations.
 */
private FileVisitor<Path> getDeleteFileVisitor() {
    return new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            file.toFile().setWritable(true);
            Files.delete(file);
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
            Files.delete(dir);
            return FileVisitResult.CONTINUE;
        }
    };
}

From source file:org.apache.beam.sdk.io.TextIOTest.java

License:asdf

@AfterClass
public static void teardownClass() throws IOException {
    Files.walkFileTree(tempFolder, new SimpleFileVisitor<Path>() {
        @Override//from  w w  w.j  a v  a2 s . com
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            Files.delete(file);
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
            Files.delete(dir);
            return FileVisitResult.CONTINUE;
        }
    });
}

From source file:org.batfish.common.plugin.PluginConsumer.java

protected final void loadPlugins() {
    for (Path pluginDir : _pluginDirs) {
        if (Files.exists(pluginDir)) {
            try {
                Files.walkFileTree(pluginDir, new SimpleFileVisitor<Path>() {
                    @Override// w w  w. j av  a 2  s  .c o  m
                    public FileVisitResult visitFile(Path path, BasicFileAttributes attrs) throws IOException {
                        loadPluginJar(path);
                        return FileVisitResult.CONTINUE;
                    }
                });
            } catch (IOException e) {
                throw new BatfishException("Error walking through plugin dir: '" + pluginDir.toString() + "'",
                        e);
            }
        }
    }
}

From source file:org.structr.web.maintenance.DirectFileImportCommand.java

@Override
public void execute(final Map<String, Object> attributes) throws FrameworkException {

    indexer = StructrApp.getInstance(securityContext).getFulltextIndexer();

    final String sourcePath = getParameterValueAsString(attributes, "source", null);
    final String modeString = getParameterValueAsString(attributes, "mode", Mode.COPY.name()).toUpperCase();
    final String existingString = getParameterValueAsString(attributes, "existing", Existing.SKIP.name())
            .toUpperCase();/*  www .  j  av  a  2s  .  c  o  m*/
    final boolean doIndex = Boolean
            .parseBoolean(getParameterValueAsString(attributes, "index", Boolean.TRUE.toString()));

    if (StringUtils.isBlank(sourcePath)) {
        throw new FrameworkException(422,
                "Please provide 'source' attribute for deployment source directory path.");
    }

    if (!EnumUtils.isValidEnum(Mode.class, modeString)) {
        throw new FrameworkException(422, "Unknown value for 'mode' attribute. Valid values are: copy, move");
    }

    if (!EnumUtils.isValidEnum(Existing.class, existingString)) {
        throw new FrameworkException(422,
                "Unknown value for 'existing' attribute. Valid values are: skip, overwrite, rename");
    }

    // use actual enums
    final Existing existing = Existing.valueOf(existingString);
    final Mode mode = Mode.valueOf(modeString);

    final List<Path> paths = new ArrayList<>();

    if (sourcePath.contains(PathHelper.PATH_SEP)) {

        final String folderPart = PathHelper.getFolderPath(sourcePath);
        final String namePart = PathHelper.getName(sourcePath);

        if (StringUtils.isNotBlank(folderPart)) {

            final Path source = Paths.get(folderPart);
            if (!Files.exists(source)) {

                throw new FrameworkException(422, "Source path " + sourcePath + " does not exist.");
            }

            if (!Files.isDirectory(source)) {

                throw new FrameworkException(422, "Source path " + sourcePath + " is not a directory.");
            }

            try {

                try (final DirectoryStream<Path> stream = Files.newDirectoryStream(source, namePart)) {

                    for (final Path entry : stream) {
                        paths.add(entry);
                    }

                } catch (final DirectoryIteratorException ex) {
                    throw ex.getCause();
                }

            } catch (final IOException ioex) {
                throw new FrameworkException(422, "Unable to parse source path " + sourcePath + ".");
            }
        }

    } else {

        // Relative path
        final Path source = Paths.get(Settings.BasePath.getValue()).resolve(sourcePath);
        if (!Files.exists(source)) {

            throw new FrameworkException(422, "Source path " + sourcePath + " does not exist.");
        }

        paths.add(source);

    }

    final SecurityContext ctx = SecurityContext.getSuperUserInstance();
    final App app = StructrApp.getInstance(ctx);
    String targetPath = getParameterValueAsString(attributes, "target", "/");
    Folder targetFolder = null;

    ctx.setDoTransactionNotifications(false);

    if (StringUtils.isNotBlank(targetPath) && !("/".equals(targetPath))) {

        try (final Tx tx = app.tx()) {

            targetFolder = app.nodeQuery(Folder.class).and(StructrApp.key(Folder.class, "path"), targetPath)
                    .getFirst();
            if (targetFolder == null) {

                throw new FrameworkException(422, "Target path " + targetPath + " does not exist.");
            }

            tx.success();
        }
    }

    String msg = "Starting direct file import from source directory " + sourcePath + " into target path "
            + targetPath;
    logger.info(msg);
    publishProgressMessage(msg);

    paths.forEach((path) -> {

        try {

            final String newTargetPath;

            // If path is a directory, create it and use it as the new target folder
            if (Files.isDirectory(path)) {

                Path parentPath = path.getParent();
                if (parentPath == null) {
                    parentPath = path;
                }

                createFileOrFolder(ctx, app, parentPath, path,
                        Files.readAttributes(path, BasicFileAttributes.class), sourcePath, targetPath, mode,
                        existing, doIndex);

                newTargetPath = targetPath + PathHelper.PATH_SEP
                        + PathHelper.clean(path.getFileName().toString());

            } else {

                newTargetPath = targetPath;
            }

            Files.walkFileTree(path, new FileVisitor<Path>() {

                @Override
                public FileVisitResult preVisitDirectory(final Path dir, final BasicFileAttributes attrs)
                        throws IOException {
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs)
                        throws IOException {
                    return createFileOrFolder(ctx, app, path, file, attrs, sourcePath, newTargetPath, mode,
                            existing, doIndex);
                }

                @Override
                public FileVisitResult visitFileFailed(final Path file, final IOException exc)
                        throws IOException {
                    return FileVisitResult.CONTINUE;
                }

                @Override
                public FileVisitResult postVisitDirectory(final Path dir, final IOException exc)
                        throws IOException {
                    return FileVisitResult.CONTINUE;
                }
            });

        } catch (final IOException ex) {
            logger.debug("Mode: " + modeString + ", path: " + sourcePath, ex);
        }
    });

    msg = "Finished direct file import from source directory " + sourcePath + ". Imported " + folderCount
            + " folders and " + fileCount + " files.";
    logger.info(msg);

    publishProgressMessage(msg);
}

From source file:com.sastix.cms.server.services.content.HashedDirectoryServiceTest.java

private int listRecursive(Path path) throws IOException {
    final int[] counter = { 0 };
    Files.walkFileTree(path, new SimpleFileVisitor<Path>() {
        @Override//w ww. j  a  va2  s.  co m
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            counter[0]++;
            LOGGER.trace("Listing: [" + counter[0] + "]\t" + file.getParent() + "/" + file.getFileName());
            return FileVisitResult.CONTINUE;
        }

        @Override
        public FileVisitResult postVisitDirectory(Path dir, IOException exc) throws IOException {
            return FileVisitResult.CONTINUE;
        }
    });
    return counter[0];
}

From source file:gov.noaa.pfel.coastwatch.util.FileVisitorDNLS.java

/** Invoked before entering a directory. */
public FileVisitResult preVisitDirectory(Path tDir, BasicFileAttributes attrs) throws IOException {

    String ttDir = String2.replaceAll(tDir.toString(), fromSlash, toSlash) + toSlash;
    if (ttDir.equals(dir)) {
        if (debugMode)
            String2.log(">> initial dir");
        return FileVisitResult.CONTINUE;
    }//from  w  w w.  j  a va2  s.  c om

    //skip because it doesn't match pathRegex?
    if (pathPattern != null && !pathPattern.matcher(ttDir).matches()) {
        if (debugMode)
            String2.log(">> doesn't match pathRegex: " + ttDir + " regex=" + pathRegex);
        return FileVisitResult.SKIP_SUBTREE;
    }

    if (directoriesToo) {
        directoryPA.add(ttDir);
        namePA.add("");
        lastModifiedPA.add(attrs.lastModifiedTime().toMillis());
        sizePA.add(0);
    }

    if (debugMode)
        String2.log(">> recursive=" + recursive + " dir=" + ttDir);
    return recursive ? FileVisitResult.CONTINUE : FileVisitResult.SKIP_SUBTREE;
}

From source file:com.ejisto.util.IOUtils.java

public static Collection<String> findAllClassesInJarFile(File jarFile) throws IOException {
    final List<String> ret = new ArrayList<>();
    Map<String, String> env = new HashMap<>();
    env.put("create", "false");
    try (FileSystem targetFs = FileSystems.newFileSystem(URI.create("jar:file:" + jarFile.getAbsolutePath()),
            env)) {/* ww  w .  j  a v  a  2 s  .  c om*/
        final Path root = targetFs.getPath("/");
        Files.walkFileTree(root, new SimpleFileVisitor<Path>() {
            @Override
            public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
                String ext = ".class";
                if (attrs.isRegularFile() && file.getFileName().toString().endsWith(ext)) {
                    String path = root.relativize(file).toString();
                    ret.add(translatePath(path.substring(0, path.length() - ext.length()), "/"));
                }
                return FileVisitResult.CONTINUE;
            }
        });
    }
    return ret;
}

From source file:de.ncoder.studipsync.Syncer.java

public boolean isSeminarInSync(Seminar seminar) throws IOException, StudipException {
    if (!checkLevel.includes(CheckLevel.Count)) {
        return true;
    }/*  w ww . j a  v  a  2s .  co m*/

    //List downloads
    final List<Download> downloads;
    browserLock.lock();
    try {
        downloads = adapter.parseDownloads(PAGE_DOWNLOADS_LATEST, false);
    } finally {
        browserLock.unlock();
    }
    if (downloads.isEmpty()) {
        //No downloads - nothing to do
        return true;
    }

    //List local files
    final List<Path> localFiles = new LinkedList<>();
    final Path storagePath = storage.resolve(seminar);
    if (!Files.exists(storagePath)) {
        //No local files despite available downloads
        log.info(marker, "Seminar is empty!");
        return false;
    }
    Files.walkFileTree(storagePath, new SimpleFileVisitor<Path>() {
        @Override
        public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException {
            localFiles.add(file);
            return FileVisitResult.CONTINUE;
        }
    });

    //Count local files
    if (localFiles.size() < downloads.size()) {
        // Missing files
        log.warn(marker, "Seminar has only " + localFiles.size() + " local file(s) of " + downloads.size()
                + " online file(s).");
        return false;
    } else {
        // Ignore surplus files
        log.debug(marker, "Seminar has deleted file(s) left! " + localFiles.size() + " local file(s) and "
                + downloads.size() + " online file(s).");
    }

    //Check local files
    if (!areFilesInSync(downloads, localFiles)) {
        return false;
    }

    return true;
}