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:edu.chalmers.dat076.moviefinder.service.MovieFileDatabaseHandlerImpl.java

@Override
@Transactional//  ww w. j a v a  2s  . c o m
public void updateFiles(List<Path> paths, Path basePath) {
    List<Movie> movies = movieRepository.findAllByFilePathStartingWith(basePath.toString());
    for (int j = 0; j < movies.size(); j++) {
        for (int i = 0; i < paths.size(); i++) {
            if (paths.get(i).toString().equals(movies.get(j).getFilePath())) {
                paths.remove(i);
                movies.remove(j);
                j--;
                break;
            }
        }
    }

    List<Episode> episodes = episodeRepository.findAllByFilePathStartingWith(basePath.toString());
    for (int j = 0; j < movies.size(); j++) {
        for (int i = 0; i < paths.size(); i++) {
            if (paths.get(i).toString().equals(episodes.get(j).getFilePath())) {
                paths.remove(i);
                episodes.remove(j);
                j--;
                break;
            }
        }
    }

    for (Path p : paths) {
        saveFile(p);
    }

    for (Movie m : movies) {
        removeFile(new File(m.getFilePath()).toPath());
    }

    for (Episode e : episodes) {
        removeFile(new File(e.getFilePath()).toPath());
    }
}

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

private void writeCsvViolations(Path folder, Map<String, List<LimitViolation>> networksViolations)
        throws IOException {
    Path csvFile = getFile(folder, "networks-violations.csv");
    System.out.println("writing pre-contingency network violations to file " + csvFile.toString());
    try (FileWriter content = new FileWriter(csvFile.toFile())) {
        CsvWriter cvsWriter = null;/*  ww w .j a v  a 2 s . c  o m*/
        try {
            cvsWriter = new CsvWriter(content, ',');
            String[] headers = new String[] { "Basecase", "Equipment", "Type", "Value", "Limit" };
            cvsWriter.writeRecord(headers);
            for (String caseBasename : networksViolations.keySet()) {
                for (LimitViolation violation : networksViolations.get(caseBasename)) {
                    String[] values = new String[] { caseBasename, violation.getSubject().getId(),
                            violation.getLimitType().name(), Float.toString(violation.getValue()),
                            Float.toString(violation.getLimit()) };
                    cvsWriter.writeRecord(values);
                }
            }
            cvsWriter.flush();
        } finally {
            if (cvsWriter != null)
                cvsWriter.close();
        }
    }
}

From source file:org.abondar.experimental.eventsearch.SearchData.java

public void indexDoc(IndexWriter iw, Path file, long lastModified) throws IOException {
    try (InputStream stream = Files.newInputStream(file)) {

        Document doc = new Document();
        Field pathField = new StringField("path", file.toString(), Field.Store.YES);
        doc.add(pathField);//from   w  w  w .  j  a v  a2  s  .c  o  m
        ObjectMapper mapper = new ObjectMapper();
        Event eb = mapper.readValue(new File(file.toString()), Event.class);
        doc.add(new TextField("category", eb.getCategory(), Field.Store.YES));

        if (iw.getConfig().getOpenMode() == OpenMode.CREATE) {
            iw.addDocument(doc);
            for (IndexableField ifd : doc.getFields()) {
                System.out.println(ifd.stringValue() + "  " + ifd.name());
            }
            System.out.println("adding " + file);

        } else {

            iw.updateDocument(new Term("path", file.toString()), doc);
            System.out.println("updating " + file);
        }

    }
}

From source file:de.flashpixx.rrd_antlr4.engine.template.IBaseTemplate.java

/**
 * copies files from the directory of the template to the output directory
 *
 * @param p_templatefile file within the template directory
 * @param p_output output directory/* w w w . j  a  v  a  2 s .co m*/
 * @throws IOException on IO error
 * @throws URISyntaxException on URL syntax error
 */
protected final void copy(final String p_templatefile, final Path p_output)
        throws IOException, URISyntaxException {
    final Path l_target = Paths.get(p_output.toString(), p_templatefile);
    Files.createDirectories(l_target.getParent());
    Files.copy(CCommon.resourceurl(MessageFormat.format("{0}{1}{2}{3}", "de/flashpixx/rrd_antlr4/template/",
            m_name, "/", p_templatefile)).openStream(), l_target, StandardCopyOption.REPLACE_EXISTING);
}

From source file:de.flashpixx.rrd_antlr4.engine.template.CLaTeXSyntax.java

@Override
public final void postprocess(final Path p_output) throws IOException, URISyntaxException {
    this.copy("index.tex", p_output);

    // replace content
    this.replace(new File(p_output.toString(), "/index.tex"),

            // set title
            "-grammartitle-", CCommon.languagestring(this, "section", m_grammar.id()),

            // set grammar documentation
            "-grammardocumentation-", m_grammar.documentation(),

            // set text rules
            "-rules-",
            StringUtils.join(//from   w w  w. j ava 2s.c  om
                    m_rules.rowMap().entrySet().stream()
                            .sorted((n, m) -> n.getKey().compareToIgnoreCase(m.getKey())).map(
                                    i -> MessageFormat
                                            .format("\\subsection*'{'{0}'}'\n" + "\\begin'{'grammar'}'"
                                                    + "\n{1}\n" + "\\end'{'grammar'}'",
                                                    CCommon.languagestring(this, "subsectiongrammar",
                                                            i.getKey()),
                                                    StringUtils
                                                            .join(i.getValue().entrySet().stream()
                                                                    .sorted((n, m) -> n.getKey()
                                                                            .compareToIgnoreCase(m.getKey()))
                                                                    .map(Map.Entry::getValue)
                                                                    .collect(Collectors.toList()), "\n")
                                                            .trim()))
                            .collect(Collectors.toList()),
                    "\n\n"));
}

From source file:com.netflix.spinnaker.halyard.deploy.spinnaker.v1.service.local.git.LocalGitDeckService.java

@Override
public List<Profile> getProfiles(DeploymentConfiguration deploymentConfiguration,
        SpinnakerRuntimeSettings endpoints) {
    List<Profile> result = new ArrayList<>();
    Profile deckProfile = deckProfileFactory.getProfile(deckSettingsPath, deckPath, deploymentConfiguration,
            endpoints);/*from   w  w  w  .j a  va2  s .  co m*/

    String deploymentName = deploymentConfiguration.getName();
    Path userProfilePath = halconfigDirectoryStructure.getUserProfilePath(deploymentName);
    Optional<Profile> settingsLocalProfile = this.customProfile(deploymentConfiguration, endpoints,
            Paths.get(userProfilePath.toString(), deckSettingsLocalPath), deckSettingsLocalPath);
    settingsLocalProfile.ifPresent(p -> deckProfile.appendContents(p.getContents()));

    result.add(deckProfile);
    return result;
}

From source file:com.hpe.caf.worker.testing.preparation.PreparationResultProcessor.java

@Override
protected Path getSaveFilePath(TestItem<TInput, TExpected> testItem, TaskMessage message) {
    Path saveFilePath = super.getSaveFilePath(testItem, message);
    if (configuration.isStoreTestCaseWithInput()) {
        Path fileName = saveFilePath.getFileName();
        Path path = Paths.get(testItem.getInputData().getInputFile());
        saveFilePath = Paths.get(configuration.getTestDataFolder(),
                path.getParent() == null ? "" : path.getParent().toString(), fileName.toString());
    }/*from   w w w .  j  a va2  s. c  o  m*/
    return saveFilePath;
}

From source file:com.thinkbiganalytics.nifi.v2.ingest.CreateElasticsearchBackedHiveTable.java

public String generateHQL(String columnsSQL, String nodes, String locationRoot, String feedName,
        String categoryName, String useWan, String autoIndex, String idField) {
    // elastic search records for the kylo-data index require the kylo_schema and kylo_table
    columnsSQL = columnsSQL + ", kylo_schema string, kylo_table string";

    // Construct location
    Path path = Paths.get(locationRoot, categoryName, feedName, "index");
    String location = path.toString().replace(":/", "://");

    StringBuilder sb = new StringBuilder();
    sb.append("CREATE EXTERNAL TABLE IF NOT EXISTS ").append(categoryName).append(".").append(feedName)
            .append("_index").append(" (").append(columnsSQL).append(") ")
            .append("STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler' ").append("LOCATION '")
            .append(location).append("' ").append("TBLPROPERTIES('es.resource' = '")
            .append(KYLO_DATA_INDEX_NAME).append("/").append(KYLO_DATA_INDEX_TYPE).append("', 'es.nodes' = '")
            .append(nodes).append("', 'es.nodes.wan.only' = '").append(useWan)
            .append("', 'es.index.auto.create' = '").append(autoIndex);

    if (idField != null && !idField.isEmpty()) {
        sb.append("', 'es.mapping.id' = '").append(idField);
    }//from ww  w.j a v a  2s  .c o  m

    sb.append("')");

    return sb.toString();
}

From source file:ws.doerr.cssinliner.server.PathSerializer.java

@Override
public void serialize(Path value, JsonGenerator gen, SerializerProvider serializers)
        throws IOException, JsonProcessingException {
    gen.writeStartObject();/*from  w  w  w. j a v  a2 s.  co m*/
    gen.writeStringField("name", value.getFileName().toString());
    gen.writeStringField("folder", value.getParent().toString());
    gen.writeStringField("path", value.toString());
    gen.writeNumberField("modified", value.toFile().lastModified());
    gen.writeEndObject();
}

From source file:ezbake.discovery.stethoscope.client.StethoscopeClient.java

@Option(name = "-P", aliases = "--additional-config-dirs", metaVar = "dir1 dir2 dir2")
void setAdditionalConfigurationDirectory(final String directory) throws CmdLineException {
    Path path = Paths.get(directory);
    if (!Files.isDirectory(path)) {
        throw new CmdLineException(path.toString() + " is not a directory!");
    }/*from w w  w. j a v  a 2  s  .  c om*/

    additionalConfigurationDirs.add(path);
}