Example usage for java.nio.file Path toString

List of usage examples for java.nio.file Path toString

Introduction

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

Prototype

String toString();

Source Link

Document

Returns the string representation of this path.

Usage

From source file:io.stallion.dataAccess.file.TomlPersister.java

@Override
public List fetchAll() {
    File target = new File(Settings.instance().getTargetFolder());
    if (!target.isDirectory()) {
        if (getItemController().isWritable()) {
            target.mkdirs();//from   w  w  w.  j a va  2  s  .c om
        } else {
            throw new ConfigException(String.format(
                    "The TOML bucket %s (path %s) is read-only, but does not exist in the file system. Either create the folder, make it writable, or remove it from the configuration.",
                    getItemController().getBucket(), getBucketFolderPath()));
        }
    }
    TreeVisitor visitor = new TreeVisitor();
    Path folderPath = FileSystems.getDefault().getPath(getBucketFolderPath());
    try {
        Files.walkFileTree(folderPath, visitor);
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
    List<Object> objects = new ArrayList<>();
    for (Path path : visitor.getPaths()) {
        if (!path.toString().toLowerCase().endsWith(".toml")) {
            continue;
        }
        if (path.toString().contains(".#")) {
            continue;
        }
        Log.fine("Load from toml file " + path);
        if (isManyItemsPerFile()) {
            try {
                Log.finer("Load toml path {0} and items {1}", path.toString(), getItemArrayName());
                String toml = FileUtils.readFileToString(new File(path.toString()), UTF8);
                Toml t = new Toml().read(toml);
                List<HashMap> models = t.getList(getItemArrayName());
                long x = 0;
                for (Map m : models) {
                    x++;
                    T o = getModelClass().newInstance();
                    for (Object key : m.keySet()) {
                        PropertyUtils.setProperty(o, key.toString(), m.get(key));
                    }
                    Log.info("add item {0}", ((MappedModel) o).get("title"));
                    if (empty(o.getId())) {
                        o.setId(x);
                    }
                    handleFetchOne(o);
                    objects.add(o);
                }
            } catch (IOException e) {
                throw new RuntimeException(e);
            } catch (IllegalAccessException e) {
                throw new RuntimeException(e);
            } catch (InstantiationException e) {
                throw new RuntimeException(e);
            }

        } else {
            objects.add(fetchOne(path.toString()));
        }

    }
    return objects;
}

From source file:eu.itesla_project.online.tools.RunTDSimulationsMpiTool.java

@Override
public void run(CommandLine line) throws Exception {

    OnlineWorkflowStartParameters startconfig = OnlineWorkflowStartParameters.loadDefault();

    String host = line.getOptionValue(OnlineWorkflowCommand.HOST);
    String port = line.getOptionValue(OnlineWorkflowCommand.PORT);
    String threads = line.getOptionValue(OnlineWorkflowCommand.THREADS);
    if (host != null)
        startconfig.setJmxHost(host);//w w w .ja  v  a  2  s .co  m
    if (port != null)
        startconfig.setJmxPort(Integer.valueOf(port));
    if (threads != null)
        startconfig.setThreads(Integer.valueOf(threads));

    String urlString = "service:jmx:rmi:///jndi/rmi://" + startconfig.getJmxHost() + ":"
            + startconfig.getJmxPort() + "/jmxrmi";

    JMXServiceURL serviceURL = new JMXServiceURL(urlString);
    Map<String, String> jmxEnv = new HashMap<>();
    JMXConnector connector = JMXConnectorFactory.connect(serviceURL, jmxEnv);
    MBeanServerConnection mbsc = connector.getMBeanServerConnection();

    ObjectName name = new ObjectName(LocalOnlineApplicationMBean.BEAN_NAME);
    LocalOnlineApplicationMBean application = MBeanServerInvocationHandler.newProxyInstance(mbsc, name,
            LocalOnlineApplicationMBean.class, false);

    boolean emptyContingency = line.hasOption("empty-contingency");
    Path caseFile = Paths.get(line.getOptionValue("case-file"));
    application.runTDSimulations(startconfig, caseFile.toString(), line.getOptionValue("contingencies"),
            Boolean.toString(emptyContingency), line.getOptionValue("output-folder"));
}

From source file:fr.cnrs.sharp.test.MainCLITest.java

@Test
public void Main1() throws IOException {
    InputStream is = MainCLITest.class.getClassLoader().getResourceAsStream("galaxy.prov.ttl");
    Path p = Files.createTempFile("test-prov", ".ttl");
    FileUtils.copyInputStreamToFile(is, p.toFile());
    System.out.println("Galaxy PROV written to " + p.toString());

    String[] params = { "-i", p.toString() };

    StopWatch sw = new StopWatch();
    sw.start();/*ww  w  .  ja  va  2 s . co  m*/
    Main.main(params);
    sw.stop();
    System.out.println("DONE in " + sw.getTime() + " ms");

}

From source file:fr.cnrs.sharp.test.MainCLITest.java

@Test
public void Main2() throws IOException {
    InputStream is = MainCLITest.class.getClassLoader().getResourceAsStream("galaxy.prov.ttl");
    Path p = Files.createTempFile("test-prov", ".ttl");
    FileUtils.copyInputStreamToFile(is, p.toFile());
    System.out.println("Galaxy PROV written to " + p.toString());

    String[] params = { "-i", p.toString(), "-s" };

    StopWatch sw = new StopWatch();
    sw.start();//from   ww  w.ja  v a2 s  . c  o m
    Main.main(params);
    sw.stop();
    System.out.println("DONE in " + sw.getTime() + " ms");

}

From source file:com.liferay.sync.engine.util.FileUtilTest.java

@Test
public void testGetNextFilePathName() throws Exception {
    Path filePath = Files.createTempFile("test", null);

    String filePathName = filePath.toString();

    String nextFilePathName = FileUtil.getNextFilePathName(filePathName);

    Assert.assertEquals(filePathName.substring(0, filePathName.length() - 4) + " (1).tmp", nextFilePathName);
}

From source file:it.sonarlint.cli.tools.SonarlintInstaller.java

private void installZip(Path zipFilePath, Path toDir) {
    try {//  ww  w . j av  a 2s  . co  m
        ZipFile zipFile = new ZipFile(zipFilePath.toFile());
        zipFile.extractAll(toDir.toString());
    } catch (Exception e) {
        throw new IllegalStateException("Fail to unzip sonarlint cli to" + toDir, e);
    }
}

From source file:its.tools.SonarlintInstaller.java

private void installZip(Path zipFilePath, Path toDir) {
    try {//from  ww w.j  a  v  a 2 s. c  o m
        ZipFile zipFile = new ZipFile(zipFilePath.toFile());
        zipFile.extractAll(toDir.toString());
    } catch (Exception e) {
        throw new IllegalStateException("Fail to unzip SonarLint Daemon to" + toDir, e);
    }
}

From source file:au.org.ands.vocabs.toolkit.provider.transform.JsonListTransformProvider.java

@Override
public final boolean transform(final TaskInfo taskInfo, final JsonNode subtask,
        final HashMap<String, String> results) {
    Path dir = Paths.get(ToolkitFileUtils.getTaskHarvestOutputPath(taskInfo));
    ConceptHandler conceptHandler = new ConceptHandler();
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
        for (Path entry : stream) {
            RDFFormat format = Rio.getParserFormatForFileName(entry.toString());
            RDFParser rdfParser = Rio.createParser(format);
            rdfParser.setRDFHandler(conceptHandler);
            FileInputStream is = new FileInputStream(entry.toString());
            rdfParser.parse(is, entry.toString());
            logger.debug("Reading RDF:" + entry.toString());

        }//w  w w. j a  va 2s. c o  m
    } catch (DirectoryIteratorException | IOException | RDFParseException | RDFHandlerException
            | UnsupportedRDFormatException ex) {
        results.put(TaskStatus.EXCEPTION, "Exception in JsonListTransform while Parsing RDF");
        logger.error("Exception in JsonListTransform while Parsing RDF:", ex);
        return false;
    }

    String resultFileName = ToolkitFileUtils.getTaskOutputPath(taskInfo, "concepts_list.json");
    try {
        File out = new File(resultFileName);
        results.put("concepts_list", resultFileName);
        HashMap<String, HashMap<String, Object>> conceptMap = conceptHandler.getConceptMap();
        FileUtils.writeStringToFile(out, TaskUtils.mapToJSONString(conceptMap));
    } catch (IOException ex) {
        results.put(TaskStatus.EXCEPTION, "Exception in JsonListTransform while Parsing RDF");
        logger.error("Exception in JsonListTransform generating result:", ex);
        return false;
    }
    return true;
}

From source file:au.org.ands.vocabs.toolkit.provider.transform.SolrIndexTransformProvider.java

@Override
public final boolean transform(final TaskInfo taskInfo, final JsonNode subtask,
        final HashMap<String, String> results) {
    Path dir = Paths.get(ToolkitFileUtils.getTaskHarvestOutputPath(taskInfo));
    ConceptHandler conceptHandler = new ConceptHandler();
    try (DirectoryStream<Path> stream = Files.newDirectoryStream(dir)) {
        for (Path entry : stream) {
            RDFFormat format = Rio.getParserFormatForFileName(entry.toString());
            RDFParser rdfParser = Rio.createParser(format);
            rdfParser.setRDFHandler(conceptHandler);
            FileInputStream is = new FileInputStream(entry.toString());
            rdfParser.parse(is, entry.toString());

            logger.debug("Reading RDF:" + entry.toString());

        }//from  www .  j  a va  2 s  .c o m
    } catch (DirectoryIteratorException | IOException | RDFParseException | RDFHandlerException ex) {
        // I/O error encountered during the iteration,
        // the cause is an IOException
        results.put(TaskStatus.EXCEPTION, "Exception in SolrIndexTransform while Parsing RDF");
        logger.error("Exception in SolrIndexTransform while Parsing RDF:", ex);
        return false;
    }

    String resultFileName = ToolkitFileUtils.getTaskOutputPath(taskInfo, "concepts_solr.json");
    try {
        FileOutputStream out = new FileOutputStream(resultFileName);
        JsonObjectBuilder job = Json.createObjectBuilder();
        job.add("concepts_count", conceptHandler.getCountedPrefLabels());
        results.put("concepts_count", Integer.toString(conceptHandler.getCountedPrefLabels()));
        job.add("concepts_text", conceptHandler.getConceptText());
        results.put("concepts_solr", resultFileName);

        JsonWriter jsonWriter = Json.createWriter(out);
        jsonWriter.writeObject(job.build());
        jsonWriter.close();
    } catch (FileNotFoundException ex) {
        results.put(TaskStatus.EXCEPTION, "Exception in SolrIndexTransform while generating result");
        logger.error("Exception in SolrIndexTransform generating result:", ex);
        return false;
    }
    return true;
}

From source file:com.zergiu.tvman.controllers.FSBrowseController.java

/**
 * @param children//  w  w  w .ja  v  a 2  s .  c om
 * @param parent
 * @return
 * @throws IOException
 */
private void addChildFolders(Map<String, String> children, Path parent) throws IOException {
    try (DirectoryStream<Path> paths = Files.newDirectoryStream(parent)) {
        for (Path path : paths) {
            if (Files.isDirectory(path)) {
                Path name = path.getFileName();
                children.put(path.toString(), name.toString());
            }
        }
    } //try
}