Example usage for java.nio.file InvalidPathException getMessage

List of usage examples for java.nio.file InvalidPathException getMessage

Introduction

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

Prototype

public String getMessage() 

Source Link

Document

Returns a string describing the error.

Usage

From source file:edu.usc.goffish.gofs.tools.GoFSDeployGraph.java

@SuppressWarnings("deprecation")
public static void main(String[] args) throws IOException {
    if (args.length < REQUIRED_ARGS) {
        PrintUsageAndQuit(null);// w w  w  . j av a  2s  .  c om
    }

    if (args.length == 1 && args[0].equals("-help")) {
        PrintUsageAndQuit(null);
    }

    // optional arguments
    boolean overwriteGraph = false;
    PartitionerMode partitionerMode = PartitionerMode.METIS;
    ComponentizerMode componentizerMode = ComponentizerMode.WCC;
    MapperMode mapperMode = MapperMode.ROUNDROBIN;
    PartitionedFileMode partitionedFileMode = PartitionedFileMode.DEFAULT;
    DistributerMode distributerMode = DistributerMode.SCP;
    int instancesGroupingSize = 1;
    int numSubgraphBins = -1;

    // optional sub arguments
    Path metisBinaryPath = null;
    String[] extraMetisOptions = null;
    Path partitioningPath = null;
    Path partitionedGMLFilePath = null;

    // parse optional arguments
    int i = 0;
    OptArgLoop: for (i = 0; i < args.length - REQUIRED_ARGS; i++) {

        switch (args[i]) {
        case "-overwriteGraph":
            overwriteGraph = true;
            break;
        case "-partitioner":
            i++;

            if (args[i].equals("stream")) {
                partitionerMode = PartitionerMode.STREAM;
            } else if (args[i].startsWith("metis")) {
                String[] subargs = parseSubArgs('=', args[i]);
                if (subargs[0].equals("metis")) {
                    partitionerMode = PartitionerMode.METIS;
                    if (subargs.length > 1) {
                        try {
                            metisBinaryPath = Paths.get(subargs[1]);
                            if (!metisBinaryPath.isAbsolute()) {
                                throw new InvalidPathException(metisBinaryPath.toString(),
                                        "metis binary path must be absolute");
                            }
                        } catch (InvalidPathException e) {
                            PrintUsageAndQuit("metis binary - " + e.getMessage());
                        }

                        if (subargs.length > 2) {
                            extraMetisOptions = parseSubArgs(' ', subargs[2]);
                        }
                    }
                } else {
                    PrintUsageAndQuit(null);
                }
            } else if (args[i].startsWith("predefined")) {
                String[] subargs = parseSubArgs('=', args[i]);
                if (subargs[0].equals("predefined")) {
                    partitionerMode = PartitionerMode.PREDEFINED;
                    if (subargs.length < 2) {
                        PrintUsageAndQuit(null);
                    }

                    try {
                        partitioningPath = Paths.get(subargs[1]);
                    } catch (InvalidPathException e) {
                        PrintUsageAndQuit("partitioning file - " + e.getMessage());
                    }
                } else {
                    PrintUsageAndQuit(null);
                }
            } else {
                PrintUsageAndQuit(null);
            }

            break;
        case "-intermediategml":
            if (args[i + 1].startsWith("save")) {
                i++;
                String[] subargs = parseSubArgs('=', args[i]);
                if (subargs[0].equals("save")) {
                    if (subargs.length < 2) {
                        PrintUsageAndQuit(null);
                    }

                    partitionedFileMode = PartitionedFileMode.SAVE;
                    try {
                        partitionedGMLFilePath = Paths.get(subargs[1]);
                    } catch (InvalidPathException e) {
                        PrintUsageAndQuit("partitioned gml file  - " + e.getMessage());
                    }
                }
            } else {
                partitionedFileMode = PartitionedFileMode.READ;
            }
            break;
        case "-componentizer":
            i++;

            switch (args[i]) {
            case "single":
                componentizerMode = ComponentizerMode.SINGLE;
                break;
            case "wcc":
                componentizerMode = ComponentizerMode.WCC;
                break;
            default:
                PrintUsageAndQuit(null);
            }

            break;
        case "-distributer":
            i++;

            switch (args[i]) {
            case "scp":
                distributerMode = DistributerMode.SCP;
                break;
            case "write":
                distributerMode = DistributerMode.WRITE;
                break;
            default:
                PrintUsageAndQuit(null);
            }

            break;
        case "-mapper":
            i++;

            if (args[i].equalsIgnoreCase("roundrobin")) {
                mapperMode = MapperMode.ROUNDROBIN;
            } else {
                PrintUsageAndQuit(null);
            }

            break;
        case "-serializer:instancegroupingsize":
            i++;

            try {
                if (args[i].equalsIgnoreCase("ALL")) {
                    instancesGroupingSize = Integer.MAX_VALUE;
                } else {
                    instancesGroupingSize = Integer.parseInt(args[i]);
                    if (instancesGroupingSize < 1) {
                        PrintUsageAndQuit("Serialization instance grouping size must be greater than zero");
                    }
                }
            } catch (NumberFormatException e) {
                PrintUsageAndQuit("Serialization instance grouping size - " + e.getMessage());
            }

            break;
        case "-serializer:numsubgraphbins":
            i++;

            try {
                numSubgraphBins = Integer.parseInt(args[i]);
                if (instancesGroupingSize < 1) {
                    PrintUsageAndQuit("Serialization number of subgraph bins must be greater than zero");
                }
            } catch (NumberFormatException e) {
                PrintUsageAndQuit("Serialization number of subgraph bins - " + e.getMessage());
            }

            break;
        default:
            break OptArgLoop;
        }
    }

    if (args.length - i < REQUIRED_ARGS) {
        PrintUsageAndQuit(null);
    }

    // required arguments
    IInternalNameNode nameNode = null;
    Class<? extends IInternalNameNode> nameNodeType = null;
    URI nameNodeLocation = null;
    String graphId = null;
    int numPartitions = 0;
    Path gmlTemplatePath = null;
    List<Path> gmlInstancePaths = new LinkedList<>();

    // parse required arguments

    try {
        nameNodeType = NameNodeProvider.loadNameNodeType(args[i]);
        i++;
    } catch (ReflectiveOperationException e) {
        PrintUsageAndQuit("name node type - " + e.getMessage());
    }

    try {
        nameNodeLocation = new URI(args[i]);
        i++;
    } catch (URISyntaxException e) {
        PrintUsageAndQuit("name node location - " + e.getMessage());
    }

    try {
        nameNode = NameNodeProvider.loadNameNode(nameNodeType, nameNodeLocation);
    } catch (ReflectiveOperationException e) {
        PrintUsageAndQuit("error loading name node - " + e.getMessage());
    }

    graphId = args[i++];

    try {
        numPartitions = Integer.parseInt(args[i]);
        i++;
    } catch (NumberFormatException e) {
        PrintUsageAndQuit("number of partitions - " + e.getMessage());
    }

    Path gmlInputFile = null;
    try {
        gmlInputFile = Paths.get(args[i]);
        i++;
    } catch (InvalidPathException e) {
        PrintUsageAndQuit(e.getMessage());
    }

    // finished parsing args
    if (i < args.length) {
        PrintUsageAndQuit("Unrecognized argument \"" + args[i] + "\"");
    }

    // ensure name node is available
    if (!nameNode.isAvailable()) {
        throw new IOException("Name node at " + nameNode.getURI() + " is not available");
    }

    // ensure there are data nodes available
    Set<URI> dataNodes = nameNode.getDataNodes();
    if (dataNodes == null || dataNodes.isEmpty()) {
        throw new IllegalArgumentException("name node does not have any data nodes available for deployment");
    }

    // ensure graph id does not exist (unless to be overwritten)
    IntCollection partitions = nameNode.getPartitionDirectory().getPartitions(graphId);
    if (partitions != null) {
        if (!overwriteGraph) {
            throw new IllegalArgumentException(
                    "graph id \"" + graphId + "\" already exists in name node partition directory");
        } else {
            for (int partitionId : partitions) {
                nameNode.getPartitionDirectory().removePartitionMapping(graphId, partitionId);
            }
        }
    }

    IGraphLoader loader = null;
    IPartitioner partitioner = null;
    if (partitionedFileMode != PartitionedFileMode.READ) {
        XMLConfiguration configuration;
        try {
            configuration = new XMLConfiguration(gmlInputFile.toFile());
            configuration.setDelimiterParsingDisabled(true);

            //read the template property
            gmlTemplatePath = Paths.get(configuration.getString("template"));

            //read the instance property
            for (Object instance : configuration.getList("instances.instance")) {
                gmlInstancePaths.add(Paths.get(instance.toString()));
            }
        } catch (ConfigurationException | InvalidPathException e) {
            PrintUsageAndQuit("gml input file - " + e.getMessage());
        }

        // create loader
        loader = new GMLGraphLoader(gmlTemplatePath);

        // create partitioner
        switch (partitionerMode) {
        case METIS:
            if (metisBinaryPath == null) {
                partitioner = new MetisPartitioner();
            } else {
                partitioner = new MetisPartitioner(metisBinaryPath, extraMetisOptions);
            }
            break;
        case STREAM:
            partitioner = new StreamPartitioner(new LDGObjectiveFunction());
            break;
        case PREDEFINED:
            partitioner = new PredefinedPartitioner(
                    MetisPartitioning.read(Files.newInputStream(partitioningPath)));
            break;
        default:
            PrintUsageAndQuit(null);
        }
    }

    // create componentizer
    IGraphComponentizer graphComponentizer = null;
    switch (componentizerMode) {
    case SINGLE:
        graphComponentizer = new SingleComponentizer();
        break;
    case WCC:
        graphComponentizer = new WCCComponentizer();
        break;
    default:
        PrintUsageAndQuit(null);
    }

    // create mapper
    IPartitionMapper partitionMapper = null;
    switch (mapperMode) {
    case ROUNDROBIN:
        partitionMapper = new RoundRobinPartitionMapper(nameNode.getDataNodes());
        break;
    default:
        PrintUsageAndQuit(null);
    }

    // create serializer
    ISliceSerializer serializer = nameNode.getSerializer();
    if (serializer == null) {
        throw new IOException("name node at " + nameNode.getURI() + " returned null serializer");
    }

    // create distributer
    IPartitionDistributer partitionDistributer = null;
    switch (distributerMode) {
    case SCP:
        partitionDistributer = new SCPPartitionDistributer(serializer, instancesGroupingSize, numSubgraphBins);
        break;
    case WRITE:
        partitionDistributer = new DirectWritePartitionDistributer(serializer, instancesGroupingSize,
                numSubgraphBins);
        break;
    }

    GMLPartitionBuilder partitionBuilder = null;
    try {
        System.out.print("Executing command: DeployGraph");
        for (String arg : args) {
            System.out.print(" " + arg);
        }
        System.out.println();

        // perform deployment
        long time = System.currentTimeMillis();
        switch (partitionedFileMode) {
        case DEFAULT:
            partitionBuilder = new GMLPartitionBuilder(graphComponentizer, gmlTemplatePath, gmlInstancePaths);
            deploy(nameNode.getPartitionDirectory(), graphId, numPartitions, loader, partitioner,
                    partitionBuilder, null, partitionMapper, partitionDistributer);
            break;
        case SAVE:
            //save partitioned gml files 
            partitionBuilder = new GMLPartitionBuilder(partitionedGMLFilePath, graphComponentizer,
                    gmlTemplatePath, gmlInstancePaths);
            //partitioned gml input file name format as graphid_numpartitions_paritioningtype_serializer
            String intermediateGMLInputFile = new StringBuffer().append(graphId).append("_")
                    .append(numPartitions).append("_").append(partitionerMode.name().toLowerCase()).append("_")
                    .append(serializer.getClass().getSimpleName().toLowerCase()).toString();
            deploy(nameNode.getPartitionDirectory(), graphId, numPartitions, loader, partitioner,
                    partitionBuilder, intermediateGMLInputFile, partitionMapper, partitionDistributer);
            break;
        case READ:
            //read partitioned gml files
            partitionBuilder = new GMLPartitionBuilder(graphComponentizer);
            partitionBuilder.new XMLConfigurationBuilder(gmlInputFile.toFile().getAbsolutePath())
                    .readIntermediateGMLFile();
            deploy(nameNode.getPartitionDirectory(), graphId, numPartitions, partitionBuilder, partitionMapper,
                    partitionDistributer);
            break;
        }

        System.out.println("finished [total " + (System.currentTimeMillis() - time) + "ms]");
    } finally {
        if (partitionBuilder != null)
            partitionBuilder.close();
    }
}

From source file:at.ac.tuwien.ims.latex2mobiformulaconv.app.Main.java

private static void parseCli(String[] args) {
    CommandLineParser parser = new PosixParser();
    try {/* www .  j  a v  a 2 s  .  c om*/
        CommandLine cmd = parser.parse(options, args);

        // Show usage, ignore other parameters and quit
        if (cmd.hasOption('h')) {
            usage();
            logger.debug("Help called, main() exit.");
            System.exit(0);
        }

        if (cmd.hasOption('d')) {
            // Activate debug markup only - does not affect logging!
            debugMarkupOutput = true;
        }

        if (cmd.hasOption('m')) {
            exportMarkup = true;
        }

        if (cmd.hasOption('t')) {
            title = cmd.getOptionValue('t');
        }

        if (cmd.hasOption('f')) {
            filename = cmd.getOptionValue('f');
        }

        if (cmd.hasOption('n')) {
            exportMarkup = true; // implicit markup export
            noMobiConversion = true;
        }

        if (cmd.hasOption('i')) {
            String[] inputValues = cmd.getOptionValues('i');
            for (String inputValue : inputValues) {
                inputPaths.add(Paths.get(inputValue));
            }
        } else {
            logger.error("You have to specify an inputPath file or directory!");
            usage();
            System.exit(1);
        }

        if (cmd.hasOption('o')) {
            String outputDirectory = cmd.getOptionValue('o');

            outputPath = Paths.get(outputDirectory).toAbsolutePath();
            logger.debug("Output path: " + outputPath.toAbsolutePath().toString());
            if (!Files.isDirectory(outputPath) && Files.isRegularFile(outputPath)) {
                logger.error("Given output directory is a file! Exiting...");

                System.exit(1);
            }

            if (!Files.exists(outputPath)) {
                Files.createDirectory(outputPath);
            }

            if (!Files.isWritable(outputPath)) {
                logger.error("Given output directory is not writable! Exiting...");
                logger.debug(outputPath.toAbsolutePath().toString());
                System.exit(1);
            }
            logger.debug("Output path: " + outputPath.toAbsolutePath().toString());

        } else {
            // Set default output directory if none is given
            outputPath = workingDirectory;
        }

        // If set, replace LaTeX Formulas with PNG images, created by
        if (cmd.hasOption("r")) {
            logger.debug("Picture Flag set");
            replaceWithPictures = true;
        }

        if (cmd.hasOption("u")) {
            logger.debug("Use calibre instead of kindlegen");
            useCalibreInsteadOfKindleGen = true;
        }

        // Executable configuration
        LatexToHtmlConverter latexToHtmlConverter = (LatexToHtmlConverter) applicationContext
                .getBean("latex2html-converter");
        if (cmd.hasOption(latexToHtmlConverter.getExecOption().getOpt())) {
            String execValue = cmd.getOptionValue(latexToHtmlConverter.getExecOption().getOpt());
            logger.info("LaTeX to HTML Executable argument was given: " + execValue);
            Path execPath = Paths.get(execValue);
            latexToHtmlConverter.setExecPath(execPath);
        }

        String htmlToMobiConverterBean = KINDLEGEN_HTML2MOBI_CONVERTER;
        if (useCalibreInsteadOfKindleGen) {
            htmlToMobiConverterBean = CALIBRE_HTML2MOBI_CONVERTER;
        }

        HtmlToMobiConverter htmlToMobiConverter = (HtmlToMobiConverter) applicationContext
                .getBean(htmlToMobiConverterBean);
        Option htmlToMobiOption = htmlToMobiConverter.getExecOption();
        if (cmd.hasOption(htmlToMobiOption.getOpt())) {
            String execValue = cmd.getOptionValue(htmlToMobiOption.getOpt());
            logger.info("HTML to Mobi Executable argument was given: " + execValue);
            try {
                Path execPath = Paths.get(execValue);
                htmlToMobiConverter.setExecPath(execPath);
            } catch (InvalidPathException e) {
                logger.error("Invalid path given for --" + htmlToMobiOption.getLongOpt() + " <"
                        + htmlToMobiOption.getArgName() + ">");
                logger.error("I will try to use your system's PATH variable...");
            }
        }

    } catch (MissingOptionException m) {

        Iterator<String> missingOptionsIterator = m.getMissingOptions().iterator();
        while (missingOptionsIterator.hasNext()) {
            logger.error("Missing required options: " + missingOptionsIterator.next() + "\n");
        }
        usage();
        System.exit(1);
    } catch (MissingArgumentException a) {
        logger.error("Missing required argument for option: " + a.getOption().getOpt() + "/"
                + a.getOption().getLongOpt() + "<" + a.getOption().getArgName() + ">");
        usage();
        System.exit(2);
    } catch (ParseException e) {
        logger.error("Error parsing command line arguments, exiting...");
        logger.error(e.getMessage(), e);
        System.exit(3);
    } catch (IOException e) {
        logger.error("Error creating output path at " + outputPath.toAbsolutePath().toString());
        logger.error(e.getMessage(), e);
        logger.error("Exiting...");
        System.exit(4);
    }
}

From source file:org.nuxeo.ecm.platform.commandline.executor.service.executors.ShellExecutor.java

/**
 * Returns the absolute path of a command looked up on the PATH or the initial string if not found.
 *
 * @since 7.10//from  w w  w. j a v  a  2  s.co m
 */
public static String getCommandAbsolutePath(String command) {
    // no lookup if the command is already an absolute path
    if (Paths.get(command).isAbsolute()) {
        return command;
    }
    List<String> extensions = Arrays.asList("", ".exe");
    // lookup for "command" or "command.exe" in the PATH
    String[] systemPaths = System.getenv("PATH").split(File.pathSeparator);
    for (String ext : extensions) {
        for (String sp : systemPaths) {
            try {
                Path path = Paths.get(sp.trim());
                if (Files.exists(path.resolve(command + ext))) {
                    return path.resolve(command + ext).toString();
                }
            } catch (InvalidPathException e) {
                log.warn("PATH environment variable contains an invalid path : " + e.getMessage());
            }
        }
    }
    // not found : return the initial string
    return command;
}