Example usage for java.nio.file InvalidPathException InvalidPathException

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

Introduction

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

Prototype

public InvalidPathException(String input, String reason) 

Source Link

Document

Constructs an instance from the given input string and reason.

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. ja va2 s .  co m*/
    }

    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:pl.hycom.jira.plugins.gitlab.integration.search.LucenePathSearcher.java

@PostConstruct
public void init() {
    if (indexPathManager.getIndexRootPath() == null) {
        throw new NullPointerException("Cannot start plugin, index root path is NULL");
    }/*from  ww w.j  a v a 2 s . c  o m*/
    Path path = Paths.get(indexPathManager.getPluginIndexRootPath(), COMMIT_INDEXER_DIRECTORY);
    if (path == null) {
        throw new InvalidPathException(getIndexPathStr(), "Index path doesn't exists");
    }
    luceneIndexPath = path;
    if (!luceneIndexPath.toFile().exists()) {
        luceneIndexPath.toFile().mkdir();
    }
}

From source file:org.artifactory.util.PathValidator.java

/**
 * Validates the the given path, throws {@link InvalidPathException} in case it's invalid.
 *
 * @param path The path to validate, it is expected to be in unix separators
 *//* ww w  .  jav a 2 s .  c o  m*/
public static void validate(String path) {

    if (StringUtils.isBlank(path)) {
        throw new InvalidPathException(path, "Path cannot be blank");
    }

    int state = STATE_OK;
    int len = path.length();
    int pos = 0;

    final char EOF = (char) -1;
    while (pos <= len) {
        char c = pos == len ? EOF : path.charAt(pos);

        // special check for whitespace
        if (c != ' ' && Character.isWhitespace(c)) {
            c = ' ';
        }
        switch (c) {
        case '/':
        case EOF:
            if (state == STATE_SPACE) {
                throw new InvalidPathException(path, "Path cannot have a slash after a space");
            } else if (state == STATE_DOT) {
                throw new InvalidPathException(path, "Path element cannot end with a dot");
            } else if (state == STATE_AMPERSAND) {
                throw new InvalidPathException(path, "Path cannot have single ampersand");
            }
            state = STATE_SLASH;
            break;

        case '&':
            if (pos == 0 || state == STATE_SLASH) {
                // We do not allow only & at a path token but it is allowed in general ('test&', '&test')
                state = STATE_AMPERSAND;
            }
            break;

        case '.':
            if (pos == 0 || state == STATE_SLASH) {
                state = STATE_DOT;
            }
            break;

        case ' ':
            if (state == STATE_SLASH) {
                throw new InvalidPathException(path, "Path cannot have a space after a slash");
            }
            state = STATE_SPACE;
            break;

        case '\\':
        case '|':
        case ':':
        case '*':
        case '?':
        case '"':
            throw new InvalidPathException(path, "Invalid path. '" + c + "' is not a valid name character");

        default:
            state = STATE_OK;
            break;
        }

        pos++;
    }
}

From source file:org.knime.knip.ilastik.nodes.headless.IlastikHeadlessNodeModel.java

/**
 *
 * @param row// www  .  j  ava  2 s  .  c  o  m
 * @param imgOpener
 * @return DataCell of new Image read from location given by m_outFiles
 * @throws Exception
 */
private DataCell readImageForRow(final DataRow row, final ScifioImgSource imgOpener) throws Exception {

    final DataCell cell_in = row.getCell(m_inputImgColIdx);

    if (cell_in.isMissing()) {
        return new MissingCell(null);
    }

    final ImgPlusValue<?> imgInValue = (ImgPlusValue<?>) cell_in;

    final RowKey key = row.getKey();

    final String path = m_outFiles.get(key);

    if (!Files.isRegularFile(Paths.get(path))) {
        throw new InvalidPathException(path, "Ilastik output file does not exist");
    }

    final ImgPlus<T> img = (ImgPlus<T>) imgOpener.getImg(path, 0);
    final ImgPlus<T> imgOut = m_outputDimensionsOverride.getBooleanValue()
            ? overrideTimeDimension(img, imgInValue)
            : img;

    final String source = imgInValue.getImgPlus().getSource();
    imgOut.setSource(source);
    imgOut.setName(key + "_result");
    final DataCell cell = m_imgPlusCellFactory.createCell(imgOut);

    return cell;
}