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:net.lldp.checksims.submission.Submission.java

/**
 * Recursively find all files matching in a directory.
 *
 * @param directory Directory to search in
 * @param glob Match pattern used to identify files to include
 * @return List of all matching files in this directory and subdirectories
 *///  ww  w . j  av  a2s.  c o  m
static Set<File> getAllMatchingFiles(File directory, String glob, boolean recursive)
        throws NoSuchFileException, NotDirectoryException {
    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());
    }

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

    Set<File> allFiles = new HashSet<>();
    Logger logs = LoggerFactory.getLogger(Submission.class);

    if (recursive) {
        logs.trace("Recursively traversing directory " + directory.getName());
    }

    // Get files in this directory
    File[] contents = directory
            .listFiles((f) -> matcher.matches(Paths.get(f.getAbsolutePath()).getFileName()) && f.isFile());

    // TODO consider mapping to absolute paths?

    // Add this directory
    Collections.addAll(allFiles, contents);

    // Get subdirectories
    File[] subdirs = directory.listFiles(File::isDirectory);

    // Recursively call on all subdirectories if specified
    if (recursive) {
        for (File subdir : subdirs) {
            allFiles.addAll(getAllMatchingFiles(subdir, glob, true));
        }
    }

    return allFiles;
}

From source file:de.tiqsolutions.hdfs.HadoopFileSystemProvider.java

static void rethrowRemoteException(RemoteException e, Path p1, Path p2) throws IOException {
    switch (e.getClassName()) {
    case "org.apache.hadoop.fs.PathIsNotEmptyDirectoryException":
        throw new DirectoryNotEmptyException(p1.toString());

    case "org.apache.hadoop.fs.PathExistsException":
    case "org.apache.hadoop.fs.FileAlreadyExistsException":
        throw new FileAlreadyExistsException(Objects.toString(p1), Objects.toString(p2),
                e.getLocalizedMessage());

    case "org.apache.hadoop.fs.PathPermissionException":
    case "org.apache.hadoop.fs.PathAccessDeniedException":
        throw new AccessDeniedException(Objects.toString(p1), Objects.toString(p2), e.getLocalizedMessage());

    case "org.apache.hadoop.fs.ParentNotDirectoryException":
    case "org.apache.hadoop.fs.DirectoryListingStartAfterNotFoundException":
    case "org.apache.hadoop.fs.PathIsNotDirectoryException":
        throw new NotDirectoryException(Objects.toString(p1));

    case "org.apache.hadoop.fs.PathIsDirectoryException":
    case "org.apache.hadoop.fs.InvalidPathException":
    case "org.apache.hadoop.fs.PathNotFoundException":
        throw new NoSuchFileException(Objects.toString(p1), Objects.toString(p2), e.getLocalizedMessage());

    case "org.apache.hadoop.fs.UnresolvedLinkException":
        throw new NotLinkException(Objects.toString(p1), Objects.toString(p2), e.getLocalizedMessage());

    case "org.apache.hadoop.fs.PathIOException":
    case "org.apache.hadoop.fs.ChecksumException":
    case "org.apache.hadoop.fs.InvalidRequestException":
    case "org.apache.hadoop.fs.UnsupportedFileSystemException":
    case "org.apache.hadoop.fs.ZeroCopyUnavailableException":

    }/*from w  w  w .jav a2  s  .c om*/

    throw new IOException(e.getLocalizedMessage(), e);
}

From source file:es.upm.dit.xsdinferencer.XSDInferencer.java

/**
 * Main method, executed when the tool is invoked as a standalone application
 * @param args an array with all the arguments passed to the application
 * @throws XSDConfigurationException if there is a problem regarding the configuration
 * @throws IOException if there is an I/O problem while reading the input XML files or writing the output files
 * @throws JDOMException if there is any problem while parsing the input XML files
 *//*from w w  w  .  ja va2 s  . c  o m*/
public static void main(String[] args) throws Exception {
    if (Arrays.asList(args).contains("--help")) {
        printHelp();
        System.exit(0);
    }
    try {
        XSDInferencer inferencer = new XSDInferencer();

        Results results = inferencer.inferSchema(args);

        Map<String, String> xsdsAsXMLStrings = results.getXSDsAsStrings();
        Map<String, String> jsonsAsStrings = results.getJsonSchemasAsStrings();
        Map<String, String> schemasAsStrings = xsdsAsXMLStrings != null ? xsdsAsXMLStrings : jsonsAsStrings;
        Map<String, String> statisticsDocumentsAsXMLStrings = results.getStatisticsAsStrings();
        File outputDirectory = null;
        for (int i = 0; i < args.length; i++) {
            if (!args[i].equalsIgnoreCase("--" + KEY_OUTPUT_DIRECTORY))
                continue;
            if (args[i + 1].startsWith("--") || i == args.length - 1)
                throw new IllegalArgumentException("Output directory parameter bad specified");
            outputDirectory = new File(args[i + 1]);
            if (!outputDirectory.exists())
                throw new FileNotFoundException("Output directory not found.");
            if (!outputDirectory.isDirectory())
                throw new NotDirectoryException(outputDirectory.getPath());
        }
        if (outputDirectory != null) {
            System.out.println("Writing results to " + outputDirectory.getAbsolutePath());

            for (String name : schemasAsStrings.keySet()) {
                File currentOutpuFile = new File(outputDirectory, name);
                FileOutputStream fOs = new FileOutputStream(currentOutpuFile);
                BufferedWriter bWriter = new BufferedWriter(new OutputStreamWriter(fOs, Charsets.UTF_8));
                bWriter.write(schemasAsStrings.get(name));
                bWriter.flush();
                bWriter.close();
            }
            if (statisticsDocumentsAsXMLStrings != null) {
                for (String name : statisticsDocumentsAsXMLStrings.keySet()) {
                    File currentOutpuFile = new File(outputDirectory, name);
                    FileWriter fWriter = new FileWriter(currentOutpuFile);
                    BufferedWriter bWriter = new BufferedWriter(fWriter);
                    bWriter.write(statisticsDocumentsAsXMLStrings.get(name));
                    bWriter.flush();
                    bWriter.close();
                }
            }
            System.out.println("Results written");
        } else {
            for (String name : schemasAsStrings.keySet()) {
                System.out.println(name + ":");
                System.out.println(schemasAsStrings.get(name));
                System.out.println();
            }
            if (statisticsDocumentsAsXMLStrings != null) {
                for (String name : statisticsDocumentsAsXMLStrings.keySet()) {
                    System.out.println(name + ":");
                    System.out.println(statisticsDocumentsAsXMLStrings.get(name));
                    System.out.println();
                }
            }
        }
    } catch (XSDInferencerException e) {
        System.err.println();
        System.err.println("Error at inference proccess: " + e.getMessage());
        e.printStackTrace();
        System.exit(1);
    }
}

From source file:es.upm.dit.xsdinferencer.XSDInferencer.java

/**
 * Method that, given the input args lists, returns a {@link List} of {@link File} object that represent the input files
 * @param args the args array, as provided by {@link XSDInferencer#main(String[])}
 * @param filenameFilter the {@link FilenameFilter} to look for input files
 * @return a {@link List} of {@link File} object that represent the input XML files
 * @throws FileNotFoundException if a file is not find
 * @throws NotDirectoryException if the path to an input directory is not a path to a directory
 *//*from   ww w .ja  v  a 2s .  c  o m*/
private List<File> getInstanceFileNames(String[] args, FilenameFilter filenameFilter)
        throws FileNotFoundException, NotDirectoryException {
    boolean somethingFound = false;
    List<File> result = new ArrayList<>();
    int startingIndex = -1;
    if (args.length < 1)
        throw new IllegalArgumentException("Input files parameter not found");
    for (int i = 0; i < args.length; i++) {
        if (args[i].equalsIgnoreCase("--" + KEY_INPUT_FILES)) {
            startingIndex = i;
            somethingFound = true;
        } else if (args[i].equalsIgnoreCase("--" + KEY_INPUT_DIRECTORY)) {
            String directoryPath = args[i + 1];
            File directory = new File(directoryPath);
            if (!directory.exists())
                throw new FileNotFoundException("XMLs input files directory not found");
            if (!directory.isDirectory())
                throw new NotDirectoryException(directoryPath);
            File[] xmlFiles = directory.listFiles(filenameFilter);
            result.addAll(Arrays.asList(xmlFiles));
            somethingFound = true;
        }
        if (i >= (args.length - 1) && !somethingFound)
            throw new IllegalArgumentException("Input files parameter not found");
    }
    for (int i = startingIndex + 1; (i < args.length && !args[i].startsWith("--")); i++) {
        if (startingIndex < 0)
            break;
        File xmlFile = new File(args[i]);
        if (!xmlFile.exists())
            throw new FileNotFoundException("XML input file not found: " + args[i]);
        result.add(xmlFile);
    }
    if (result.size() < 1)
        throw new IllegalArgumentException("Input files not found");
    return result;
}

From source file:de.prozesskraft.pramp.parts.PrampPartUi1.java

/**
 * determines all subdirectories of a specified directory
 * @return a list of all subdirectory names (without path - only the last name)
 * @throws NotDirectoryException /*from  ww w . j  a v a  2  s  .  c  om*/
 */
private ArrayList<String> getSubDirectories(String path) throws NotDirectoryException {
    ArrayList<String> subdirectories = new ArrayList<String>();
    File dir = new File(path);
    if (!(dir.isDirectory())) {
        throw new NotDirectoryException(path);
    }

    File[] inhaltDir = dir.listFiles();
    for (int x = 0; x < inhaltDir.length; x++) {
        if (inhaltDir[x].isDirectory()) {
            subdirectories.add(inhaltDir[x].getName());
        }
    }
    // sortieren
    //      Collections.sort(processes);
    return subdirectories;
}