Example usage for java.nio.file NotDirectoryException NotDirectoryException

List of usage examples for java.nio.file NotDirectoryException NotDirectoryException

Introduction

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

Prototype

public NotDirectoryException(String file) 

Source Link

Document

Constructs an instance of this class.

Usage

From source file:com.pixlabs.web.utils.Mp3Finder.java

/**
 * @param path Path of the directory that should be looked into.
 * @return a linkedlist containing all the Mp3 files found in the directory.
 * @throws NotDirectoryException The given path was not a directory.
 */// w w  w .j  av a 2 s . c om

public static LinkedList<Mp3FileAdvanced> mp3InDirectory(Path path) throws NotDirectoryException {
    if (!Files.isDirectory(path))
        throw new NotDirectoryException("The chosen path does not represent a directory");
    LinkedList<Mp3FileAdvanced> list = new LinkedList<>();
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(path, "*.mp3")) {
        for (Path entry : stream) {
            //       if(!entry.startsWith("."))
            list.add(new Mp3FileAdvanced(entry.toFile()));
        }

    } catch (IOException | UnsupportedTagException | InvalidDataException e) {
        e.printStackTrace();
    }
    return list;
}

From source file:com.leverno.ysbos.harvest.FileHarvester.java

public Collection<File> getFilesFor(String rootDirectoryPath) throws NotDirectoryException {
    File rootDirectory = new File(rootDirectoryPath);
    if (!rootDirectory.isDirectory()) {
        throw new NotDirectoryException(rootDirectoryPath);
    }//from   ww  w.j  a  v  a  2 s.  c  om

    return getFilesFor(rootDirectory);
}

From source file:edu.wpi.checksims.submission.Submission.java

/**
 * Generate a list of all student submissions from a directory.
 *
 * The directory is assumed to hold a number of subdirectories, each containing one student or group's submission
 * The student/group directories may contain subdirectories with files
 *
 * @param directory Directory containing student submission directories
 * @param glob Match pattern used to identify files to include in submission
 * @param splitter Tokenizes files to produce Token Lists for a submission
 * @return Set of submissions including all unique nonempty submissions in the given directory
 * @throws java.io.IOException Thrown on error interacting with file or filesystem
 */// w  w w.  jav a 2s .  c om
static Set<Submission> submissionListFromDir(File directory, String glob, Tokenizer splitter, boolean recursive)
        throws IOException {
    checkNotNull(directory);
    checkNotNull(glob);
    checkArgument(!glob.isEmpty(), "Glob pattern cannot be empty!");
    checkNotNull(splitter);

    Set<Submission> submissions = new HashSet<>();
    Logger local = LoggerFactory.getLogger(Submission.class);

    if (!directory.exists()) {
        throw new NoSuchFileException("Does not exist: " + directory.getAbsolutePath());
    } else if (!directory.isDirectory()) {
        throw new NotDirectoryException("Not a directory: " + directory.getAbsolutePath());
    }

    // List all the subdirectories we find
    File[] contents = directory.listFiles(File::isDirectory);

    for (File f : contents) {
        try {
            Submission s = submissionFromDir(f, glob, splitter, recursive);
            submissions.add(s);
            if (s.getContentAsString().isEmpty()) {
                local.warn("Warning: Submission " + s.getName() + " is empty!");
            } else {
                local.debug("Created submission with name " + s.getName());
            }
        } catch (NoMatchingFilesException e) {
            local.warn("Could not create submission from directory " + f.getName()
                    + " - no files matching pattern found!");
        }
    }

    return submissions;
}

From source file:company.gonapps.loghut.utils.FileUtils.java

public static void rmdir(Path directoryPath, DirectoryStream.Filter<Path> ignoringFilter)
        throws NotDirectoryException, IOException {
    if (!directoryPath.toFile().isDirectory())
        throw new NotDirectoryException(directoryPath.toString());

    try (DirectoryStream<Path> directoryStream = Files.newDirectoryStream(directoryPath)) {
        List<Path> ignoredPaths = new LinkedList<>();

        for (Path path : directoryStream) {
            if (!ignoringFilter.accept(path))
                return;
            ignoredPaths.add(path);//from  w  w  w  .  j  av a2 s . com
        }

        for (Path ignoredPath : ignoredPaths) {
            Files.delete(ignoredPath);
        }

        Files.delete(directoryPath);
    }
}

From source file:org.phenotips.textanalysis.internal.BiolarkFileUtils.java

/**
 * Builds project in target directory, by executing 'make clean && make'.
 *
 * @param target directory containing makefile
 * @param runtime the Runtime instance of this application
 * @throws BuildException if the build failed
 * @throws NotDirectoryException if target is not a directory
 *//*from  w w  w  . java  2 s.c o  m*/
public static void make(File target, Runtime runtime) throws BuildException, NotDirectoryException {
    if (target.isDirectory()) {
        try {
            Process p = Runtime.getRuntime().exec("make -B", null, target);
            p.waitFor();
            if (p.exitValue() != 0) {
                IOUtils.copy(p.getErrorStream(), System.out);
                throw new BuildException("Build failed in " + target.getAbsolutePath());
            }
        } catch (IOException e) {
            throw new BuildException(e.getMessage());
        } catch (InterruptedException e) {
            throw new BuildException(e.getMessage());
        }
    } else {
        throw new NotDirectoryException(target.getPath());
    }
}

From source file:net.lldp.checksims.submission.Submission.java

/**
 * Generate a list of all student submissions from a directory.
 *
 * The directory is assumed to hold a number of subdirectories, each containing one student or group's submission
 * The student/group directories may contain subdirectories with files
 *
 * @param directory Directory containing student submission directories
 * @param glob Match pattern used to identify files to include in submission
 * @param splitter Tokenizes files to produce Token Lists for a submission
 * @return Set of submissions including all unique nonempty submissions in the given directory
 * @throws java.io.IOException Thrown on error interacting with file or filesystem
 *///from w  w w .j a v a  2  s . co  m
static Set<Submission> submissionListFromDir(File directory, String glob, boolean recursive)
        throws IOException {
    checkNotNull(directory);
    checkNotNull(glob);
    checkArgument(!glob.isEmpty(), "Glob pattern cannot be empty!");

    Set<Submission> submissions = new HashSet<>();
    Logger local = LoggerFactory.getLogger(Submission.class);

    if (!directory.exists()) {
        throw new NoSuchFileException("Does not exist: " + directory.getAbsolutePath());
    } else if (!directory.isDirectory()) {
        throw new NotDirectoryException("Not a directory: " + directory.getAbsolutePath());
    }

    // List all the subdirectories we find
    File[] contents = directory.listFiles(File::isDirectory);

    for (File f : contents) {
        try {
            Submission s = submissionFromDir(f, glob, recursive);
            submissions.add(s);
            if (s.getContentAsString().isEmpty()) {
                local.warn("Warning: Submission " + s.getName() + " is empty!");
            } else {
                local.debug("Created submission with name " + s.getName());
            }
        } catch (NoMatchingFilesException e) {
            local.warn("Could not create submission from directory " + f.getName()
                    + " - no files matching pattern found!");
        }
    }

    return submissions;
}

From source file:edu.wpi.checksims.submission.Submission.java

/**
 * Get a single submission from a directory.
 *
 * @param directory Directory containing the student's submission
 * @param glob Match pattern used to identify files to include in submission
 * @param splitter Tokenizes files to produce Token List in this submission
 * @return Single submission from all files matching the glob in given directory
 * @throws IOException Thrown on error interacting with file
 *//*from  ww  w .  j  av a2 s .  com*/
static Submission submissionFromDir(File directory, String glob, Tokenizer splitter, boolean recursive)
        throws IOException, NoMatchingFilesException {
    checkNotNull(directory);
    checkNotNull(glob);
    checkArgument(!glob.isEmpty(), "Glob pattern cannot be empty!");
    checkNotNull(splitter);

    if (!directory.exists()) {
        throw new NoSuchFileException("Does not exist: " + directory.getAbsolutePath());
    } else if (!directory.isDirectory()) {
        throw new NotDirectoryException("Not a directory: " + directory.getAbsolutePath());
    }

    // TODO consider verbose logging of which files we're adding to the submission?

    Set<File> files = getAllMatchingFiles(directory, glob, recursive);

    return submissionFromFiles(directory.getName(), files, splitter);
}

From source file:com.github.fge.ftpfs.io.commonsnetimpl.CommonsNetFtpAgent.java

private static void handleFailedDirectoryList(final String dir, final FTPFile file) throws FileSystemException {
    throw file.isDirectory() ? new AccessDeniedException(dir) : new NotDirectoryException(dir);
}

From source file:net.lldp.checksims.submission.Submission.java

/**
 * Get a single submission from a directory.
 *
 * @param directory Directory containing the student's submission
 * @param glob Match pattern used to identify files to include in submission
 * @param splitter Tokenizes files to produce Token List in this submission
 * @return Single submission from all files matching the glob in given directory
 * @throws IOException Thrown on error interacting with file
 *//*from  www .j  a v a  2 s .  c o  m*/
static Submission submissionFromDir(File directory, String glob, boolean recursive)
        throws IOException, NoMatchingFilesException {
    checkNotNull(directory);
    checkNotNull(glob);
    checkArgument(!glob.isEmpty(), "Glob pattern cannot be empty!");

    if (!directory.exists()) {
        throw new NoSuchFileException("Does not exist: " + directory.getAbsolutePath());
    } else if (!directory.isDirectory()) {
        throw new NotDirectoryException("Not a directory: " + directory.getAbsolutePath());
    }

    // TODO consider verbose logging of which files we're adding to the submission?

    Set<File> files = getAllMatchingFiles(directory, glob, recursive);

    return submissionFromFiles(directory.getName(), files);
}

From source file:edu.wpi.checksims.submission.Submission.java

/**
 * Identify all files matching in a single directory.
 *
 * @param directory Directory to find files within
 * @param glob Match pattern used to identify files to include
 * @return Array of files which match in this single directory
 *//* www  .  j  av  a 2  s  .  c o  m*/
static File[] getMatchingFilesFromDir(File directory, String glob)
        throws NoSuchFileException, NotDirectoryException {
    checkNotNull(directory);
    checkNotNull(glob);
    checkArgument(!glob.isEmpty(), "Glob pattern cannot be empty");

    PathMatcher matcher = FileSystems.getDefault().getPathMatcher("glob:" + glob);

    if (!directory.exists()) {
        throw new NoSuchFileException("Does not exist: " + directory.getAbsolutePath());
    } else if (!directory.isDirectory()) {
        throw new NotDirectoryException("Not a directory: " + directory.getAbsolutePath());
    }

    return directory.listFiles((f) -> matcher.matches(Paths.get(f.getAbsolutePath()).getFileName()));
}