List of usage examples for java.nio.file Paths get
public static Path get(URI uri)
From source file:eu.itesla_project.modules.offline.ExportSecurityIndexesTool.java
@Override public void run(CommandLine line) throws Exception { String simulationDbName = line.hasOption("simulation-db-name") ? line.getOptionValue("simulation-db-name") : OfflineConfig.DEFAULT_SIMULATION_DB_NAME; OfflineConfig config = OfflineConfig.load(); OfflineDb offlineDb = config.getOfflineDbFactoryClass().newInstance().create(simulationDbName); String workflowId = line.getOptionValue("workflow"); Path outputFile = Paths.get(line.getOptionValue("output-file")); char delimiter = ';'; if (line.hasOption("delimiter")) { String value = line.getOptionValue("delimiter"); if (value.length() != 1) { throw new RuntimeException("A character is expected"); }//from w w w . ja va2s . com delimiter = value.charAt(0); } OfflineAttributesFilter stateAttrFilter = OfflineAttributesFilter.ALL; if (line.hasOption("attributes-filter")) { stateAttrFilter = OfflineAttributesFilter.valueOf(line.getOptionValue("attributes-filter")); } boolean addSampleColumn = line.hasOption("add-sample-column"); boolean keepAllSamples = line.hasOption("keep-all-samples"); try (Writer writer = Files.newBufferedWriter(outputFile, StandardCharsets.UTF_8)) { offlineDb.exportCsv(workflowId, writer, new OfflineDbCsvExportConfig(delimiter, stateAttrFilter, addSampleColumn, keepAllSamples)); } }
From source file:io.github.dustalov.maxmax.Application.java
private static void write(String filename, MaxMax<String> maxmax) throws IOException { try (final BufferedWriter writer = Files.newBufferedWriter(Paths.get(filename))) { int i = 0; for (final Set<String> cluster : maxmax.getClusters()) { writer.write(String.format(Locale.ROOT, "%d\t%d\t%s\n", i++, cluster.size(), String.join(", ", cluster))); }/*ww w. j a va 2s . com*/ } }
From source file:com.difference.historybook.importer.HistoryRecordJSONSerialization.java
/** * Stream a JSON file of HistoryRecords// w w w .j a va 2 s. co m * * @param filename filename to read * @return a stream of HistoryRecord objects parsed from file * @throws IOException */ public static Stream<HistoryRecord> parseFile(String filename) throws IOException { return Files.lines(Paths.get(filename)).map(HistoryRecordJSONSerialization::parse); }
From source file:gndata.lib.config.ProjectConfig.java
/** * Loads the project settings from a json file. * If the file does not exist, a default configuration is created. * * @param projectPath Path to the project config file. * * @return The loaded configuration.//from w ww.ja va 2 s.com * * @throws IOException If the loading fails. */ public static ProjectConfig load(String projectPath) throws IOException { Path absPath = Paths.get(projectPath).toAbsolutePath().normalize(); Path filePath = absPath.resolve(IN_PROJECT_PATH); if (Files.exists(filePath)) { ProjectConfig config = AbstractConfig.load(filePath.toString(), ProjectConfig.class); config.setProjectPath(absPath.toString()); return config; } else { ProjectConfig config = new ProjectConfig(); // set defaults here if necessary config.setFilePath(filePath.toString()); config.setProjectPath(absPath.toString()); config.store(); return config; } }
From source file:com.netflix.nicobar.core.archive.SingleFileScriptArchiveTest.java
@Test public void testDefaultModuleSpec() throws Exception { URL rootPathUrl = getClass().getClassLoader().getResource(TEST_SCRIPTS_PATH.getResourcePath()); Path rootPath = Paths.get(rootPathUrl.toURI()).toAbsolutePath(); Set<String> singleFileScripts = TEST_SCRIPTS_PATH.getContentPaths(); for (String script : singleFileScripts) { Path scriptPath = rootPath.resolve(script); SingleFileScriptArchive scriptArchive = new SingleFileScriptArchive.Builder(scriptPath).build(); String moduleId = script.replaceAll("\\.", "_"); assertEquals(scriptArchive.getModuleSpec().getModuleId().toString(), moduleId); Set<String> archiveEntryNames = scriptArchive.getArchiveEntryNames(); assertEquals(archiveEntryNames.size(), 1); for (String entryName : archiveEntryNames) { URL entryUrl = scriptArchive.getEntry(entryName); assertNotNull(entryUrl);/*from w ww .j a va 2s . c om*/ InputStream inputStream = entryUrl.openStream(); String content = IOUtils.toString(inputStream, Charsets.UTF_8); // We have stored the file name as the content of the file assertEquals(content, script + lineSeparator()); } } }
From source file:ch.oakmountain.tpa.web.TpaWebPersistor.java
public static void createGraph(String name, String outputDir, IGraph graph, String htmlData) throws IOException { LOGGER.info("Creating graph " + name + "...."); String content = IOUtils.toString(TpaWebPersistor.class.getResourceAsStream("/graph-curved.html")); content = content.replaceAll(Pattern.quote("$CSVNAME$"), Matcher.quoteReplacement(name)) .replaceAll(Pattern.quote("$HTML$"), Matcher.quoteReplacement(htmlData)); FileUtils.writeStringToFile(Paths.get(outputDir + File.separator + name + ".html").toFile(), content); File file = new File(outputDir + File.separator + name + ".csv"); writeGraph(file, graph);/*from www.jav a2 s . c o m*/ TpaPersistorUtils.copyFromResourceToDir("d3.v3.js", outputDir); LOGGER.info("... created graph " + name + "."); }
From source file:de.ks.option.properties.PropertiesOptionSource.java
public static void cleanup() { String path = getPropertiesFile(); if (new File(path).exists()) { try {/*from www .j a v a 2s . co m*/ Files.delete(Paths.get(path)); } catch (IOException e) { log.error("Could not clean up {}", path, e); } } }
From source file:edu.usc.goffish.gofs.tools.deploy.SCPPartitionDistributer.java
public SCPPartitionDistributer(ISliceSerializer serializer, int instancesGroupingSize, int numSubgraphBins) { this(Paths.get(DefaultSCPBinary), null, serializer, instancesGroupingSize, numSubgraphBins); }