Example usage for java.nio.file Paths get

List of usage examples for java.nio.file Paths get

Introduction

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

Prototype

public static Path get(URI uri) 

Source Link

Document

Converts the given URI to a Path object.

Usage

From source file:com.olacabs.fabric.executor.impl.FileMetadataSource.java

@Override
public ComputationSpec load(String path) throws Exception {
    return objectMapper.readValue(Files.readAllBytes(Paths.get(path)), ComputationSpec.class);
}

From source file:io.github.dustalov.maxmax.Application.java

private static <T> T parse(String filename, Function<Stream<String>, T> f) throws IOException {
    try (final Stream<String> stream = Files.lines(Paths.get(filename))) {
        return f.apply(stream);
    }/*from w w  w.j av a  2  s  .  co  m*/
}

From source file:IrqaQuery.java

public static void makeIndexWriter(String indexPath, String stopPath, String sim) throws IOException {
    System.out.println("[makeIndexWriter] started");
    System.out.println("[makeIndexWriter]" + stopPath);
    Directory dir = FSDirectory.open(Paths.get(indexPath));
    Analyzer analyzer = new EnglishAnalyzer(StopFilter.makeStopSet(mygetStopwords(stopPath)));
    IndexWriterConfig iwc = new IndexWriterConfig(analyzer);

    if (sim.equals("TFIDF"))
        iwc.setSimilarity(new ClassicSimilarity());
    else if (sim.equals("BM25"))
        iwc.setSimilarity(new BM25Similarity());
    else//from w ww .j av a 2  s  .c o  m
        iwc.setSimilarity(new BM25Similarity());

    writer = new IndexWriter(dir, iwc);
}

From source file:com.orasi.sandbox.TestCSVDataProvider.java

public Path getFilePath(String name) throws Throwable {
    return Paths.get(getClass().getResource(Constants.SANDBOX_PATH).toURI()).resolve(name);
}

From source file:com.orange.clara.pivotaltrackermirror.util.Swagger2MarkupTest.java

@Test
@Ignore/*from   w w  w.j a  v  a2 s .c o  m*/
public void convertRemoteSwaggerToAsciiDoc() throws MalformedURLException {
    // Remote Swagger source
    Swagger2MarkupConverter.from(new URL("http://localhost:8080/swagger/api-docs")).build()
            .toFile(Paths.get("src/docs/asciidoc/generated/api"));
}

From source file:ch.oakmountain.tpa.web.TablePersistor.java

public TablePersistor(String name, String outputDir, String title, List<String> header) throws IOException {
    this.file = Paths.get(outputDir + File.separator + name + ".html").toFile();
    createTable(name, outputDir, title, header);
}

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);//from www .ja  v a  2  s  .c o  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:io.fabric8.vertx.maven.plugin.ConfigConversionUtilTest.java

@Test
public void convertSimpleYamlToJson() throws Exception {
    Path yamlFile = Paths.get(this.getClass().getResource("/testconfig.yaml").toURI());
    Path jsonFilePath = Files.createTempFile("testconfig", ".json");
    assertNotNull(yamlFile);/*from w ww  .j  av a 2  s.  c  om*/
    assertTrue(yamlFile.toFile().isFile());
    assertTrue(yamlFile.toFile().exists());
    ConfigConverterUtil.convertYamlToJson(yamlFile, jsonFilePath);
    assertNotNull(jsonFilePath);
    String jsonDoc = new String(Files.readAllBytes(jsonFilePath));
    assertNotNull(jsonDoc);
    JSONObject jsonMap = new JSONObject(jsonDoc);
    assertNotNull(jsonMap);
    assertEquals(jsonMap.get("http.port"), 8080);

}

From source file:io.anserini.doc.GenerateRegressionDocsTest.java

@Test
public void main() throws Exception {
    ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
    URL resource = GenerateRegressionDocsTest.class.getResource("/regression/all.yaml");
    DataModel data = mapper.readValue(Paths.get(resource.toURI()).toFile(), DataModel.class);
    //System.out.println(ReflectionToStringBuilder.toString(data, ToStringStyle.MULTI_LINE_STYLE));

    for (String collection : data.getCollections().keySet()) {
        Map<String, String> valuesMap = new HashMap<>();
        valuesMap.put("index_cmds", data.generateIndexingCommand(collection));
        valuesMap.put("ranking_cmds", data.generateRankingCommand(collection));
        valuesMap.put("eval_cmds", data.generateEvalCommand(collection));
        valuesMap.put("effectiveness", data.generateEffectiveness(collection));
        StrSubstitutor sub = new StrSubstitutor(valuesMap);
        URL template = GenerateRegressionDocsTest.class
                .getResource(String.format("/docgen/templates/%s.template", collection));
        Scanner scanner = new Scanner(Paths.get(template.toURI()).toFile(), "UTF-8");
        String text = scanner.useDelimiter("\\A").next();
        scanner.close();/* ww w .  j ava 2s  . c  o  m*/
        String resolvedString = sub.replace(text);

        FileUtils.writeStringToFile(new File(String.format("docs/experiments-%s.md", collection)),
                resolvedString, "UTF-8");
    }
}

From source file:io.pivotal.ecosystem.servicebroker.service.CatalogService.java

private static String getContents(String fileName) throws IOException {
    URI u = new ClassPathResource(fileName).getURI();
    return new String(Files.readAllBytes(Paths.get(u)));
}