List of usage examples for java.nio.file Path resolve
default Path resolve(String other)
From source file:com.facebook.buck.zip.Unzip.java
public static ImmutableList<Path> extractZipFile(Path zipFile, final Path destination, ExistingFileMode existingFileMode) throws IOException { // Create output directory if it does not exist Files.createDirectories(destination); return extractZipFile(zipFile, new ProjectFilesystem(destination), destination.getFileSystem().getPath(""), existingFileMode).stream().map(input -> destination.resolve(input).toAbsolutePath()) .collect(MoreCollectors.toImmutableList()); }
From source file:fr.pilato.elasticsearch.crawler.fs.util.FsCrawlerUtil.java
/** * Reads a mapping from config/_default/version/type.json file * * @param config Root dir where we can find the configuration (default to ~/.fscrawler) * @param version Elasticsearch major version number (only major digit is kept so for 2.3.4 it will be 2) * @param type The expected type (will be expanded to type.json) * @return the mapping/* ww w . jav a 2 s. c o m*/ * @throws URISyntaxException * @throws IOException */ public static String readDefaultMapping(Path config, String version, String type) throws URISyntaxException, IOException { Path defaultConfigDir = config.resolve("_default"); try { return readMapping(defaultConfigDir, version, type); } catch (NoSuchFileException e) { throw new IllegalArgumentException( "Mapping file " + type + ".json does not exist for elasticsearch version " + version + " in [" + defaultConfigDir + "] dir"); } }
From source file:org.hawkular.apm.api.services.ConfigurationLoader.java
/** * This method constructs a path based on potentially accessing * one or more archive files (jar/war)./*ww w .j a va 2s. c o m*/ * * @param startindex The start index * @param uriParts The parts of the URI * @return The path */ protected static Path getPath(int startindex, String[] uriParts) { Path ret = Paths.get("/"); List<FileSystem> toClose = new ArrayList<FileSystem>(); try { for (int i = startindex; i < uriParts.length; i++) { String name = uriParts[i]; if (name.endsWith("!")) { name = name.substring(0, name.length() - 1); } ret = ret.resolve(name); if (name.endsWith(".jar") || name.endsWith(".war")) { try (FileSystem jarfs = FileSystems.newFileSystem(ret, Thread.currentThread().getContextClassLoader())) { ret = jarfs.getRootDirectories().iterator().next(); } catch (IOException e) { log.log(Level.SEVERE, "Failed to access archive '" + name + "'", e); } } } } finally { for (FileSystem fs : toClose) { try { fs.close(); } catch (IOException e) { log.log(Level.SEVERE, "Failed to close file system '" + fs + "'", e); } } } return ret; }
From source file:com.excelsiorjet.api.util.Utils.java
public static void copyDirectory(Path source, Path target) throws IOException { Files.walkFileTree(source, new FileVisitor<Path>() { @Override// w w w .j a va 2 s . co m public FileVisitResult preVisitDirectory(Path subfolder, BasicFileAttributes attrs) throws IOException { Files.createDirectories(target.resolve(source.relativize(subfolder))); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFile(Path sourceFile, BasicFileAttributes attrs) throws IOException { Path targetFile = target.resolve(source.relativize(sourceFile)); copyFile(sourceFile, targetFile); return FileVisitResult.CONTINUE; } @Override public FileVisitResult visitFileFailed(Path sourceFile, IOException e) throws IOException { throw new IOException(Txt.s("Utils.CannotCopyFile.Error", sourceFile.toString(), e.getMessage()), e); } @Override public FileVisitResult postVisitDirectory(Path source, IOException ioe) throws IOException { return FileVisitResult.CONTINUE; } }); }
From source file:com.qwazr.server.configuration.ServerConfiguration.java
private static Path getTempDirectory(final Path dataDir, final String value) { return StringUtils.isEmpty(value) ? dataDir.resolve("tmp") : Paths.get(value); }
From source file:controllers.ImageBrowser.java
@ModelAccess(AccessType.FILE_UPLOAD) public static void upload(File file, Path path) { File destination = path.resolve(file.getName()).toFile(); try {/*from ww w. ja v a2s .c o m*/ FileUtils.copyFile(file, destination); } catch (IOException e) { error(e); } ok(); }
From source file:eu.itesla_project.modules.validation.OfflineValidationTool.java
private static void writeComparisonFiles(Set<RuleId> rulesIds, Map<String, Map<RuleId, ValidationStatus>> statusPerRulePerCase, Path outputDir) throws IOException { for (RuleId ruleId : rulesIds) { Path comparisonFile = outputDir.resolve("comparison_" + ruleId.toString() + ".csv"); System.out.println("writing " + comparisonFile + "..."); try (BufferedWriter writer = Files.newBufferedWriter(comparisonFile, StandardCharsets.UTF_8)) { writer.write("base case"); writer.write(CSV_SEPARATOR); writer.write("simulation"); writer.write(CSV_SEPARATOR); writer.write("rule"); writer.newLine();/*w w w . j a v a 2 s .com*/ for (Map.Entry<String, Map<RuleId, ValidationStatus>> e : statusPerRulePerCase.entrySet()) { String baseCaseName = e.getKey(); Map<RuleId, ValidationStatus> statusPerRule = e.getValue(); writer.write(baseCaseName); ValidationStatus status = statusPerRule.get(ruleId); if (status == null) { status = new ValidationStatus(null, null); } writer.write(CSV_SEPARATOR); writer.write(status.isSimulationOkToStr()); writer.write(CSV_SEPARATOR); writer.write(status.isRuleOkToStr()); writer.newLine(); } } } }
From source file:de.dal33t.powerfolder.util.ConfigurationLoader.java
/** * #2467: Set server URL via command line option in installer * * @param controller/*from w ww .j a v a2 s. c o m*/ * @return */ public static boolean loadAndMergeFromInstaller(Controller controller) { Path initFile = null; String windir = System.getenv("WINDIR"); if (StringUtils.isNotBlank(windir)) { Path tempDir = Paths.get(windir).resolve("TEMP"); initFile = tempDir.resolve(INITIAL_STARTUP_CONFIG_FILENAME); } if (initFile == null || Files.notExists(initFile)) { String tempStr = System.getProperty("java.io.tmpdir"); initFile = Paths.get(tempStr).resolve(INITIAL_STARTUP_CONFIG_FILENAME); if (Files.notExists(initFile)) { return false; } } String url = ""; boolean delete = false; try (InputStream in = Files.newInputStream(initFile)) { Properties props = new Properties(); props.load(in); url = props.getProperty(ConfigurationEntry.CONFIG_URL.getConfigKey()); if (StringUtils.isBlank(url)) { String fn = props.getProperty(ConfigurationEntry.INSTALLER_FILENAME.getConfigKey()); if (StringUtils.isNotBlank(fn)) { url = PathUtils.decodeURLFromFilename(fn); } } if (StringUtils.isBlank(url)) { return false; } Properties preConfig = loadPreConfiguration(url); if (preConfig == null) { return false; } int i = merge(preConfig, controller); LOG.info("Startup " + i + " with server " + url); if (i > 0) { ConfigurationEntry.CONFIG_URL.setValue(controller, url); controller.saveConfig(); } delete = true; return true; } catch (Exception e) { LOG.warning("Unable to read configuration " + initFile + " / " + url + ". " + e); } finally { if (delete) { try { Files.delete(initFile); } catch (IOException ioe) { LOG.fine("Unable to deleted file " + initFile + ". " + ioe); } } } return false; }
From source file:eu.itesla_project.modules.validation.OfflineValidationTool.java
private static void writeAttributesFiles(Set<RuleId> rulesIds, Map<String, Map<RuleId, Map<HistoDbAttributeId, Object>>> valuesPerRulePerCase, Path outputDir) throws IOException { for (RuleId ruleId : rulesIds) { Path attributesFile = outputDir.resolve("attributes_" + ruleId.toString() + ".csv"); System.out.println("writing " + attributesFile + "..."); try (BufferedWriter writer = Files.newBufferedWriter(attributesFile, StandardCharsets.UTF_8)) { writer.write("base case"); Set<HistoDbAttributeId> allAttributeIds = new LinkedHashSet<>(); for (Map<RuleId, Map<HistoDbAttributeId, Object>> valuesPerRule : valuesPerRulePerCase.values()) { Map<HistoDbAttributeId, Object> values = valuesPerRule.get(ruleId); if (values != null) { allAttributeIds.addAll(values.keySet()); }/*from w w w . j ava 2 s . com*/ } for (HistoDbAttributeId attributeId : allAttributeIds) { writer.write(CSV_SEPARATOR); writer.write(attributeId.toString()); } writer.newLine(); for (Map.Entry<String, Map<RuleId, Map<HistoDbAttributeId, Object>>> e : valuesPerRulePerCase .entrySet()) { String baseCaseName = e.getKey(); Map<RuleId, Map<HistoDbAttributeId, Object>> valuesPerRule = e.getValue(); writer.write(baseCaseName); Map<HistoDbAttributeId, Object> values = valuesPerRule.get(ruleId); for (HistoDbAttributeId attributeId : allAttributeIds) { writer.write(CSV_SEPARATOR); Object value = values.get(attributeId); if (value != null && !(value instanceof Float && Float.isNaN((Float) value))) { writer.write(Objects.toString(values.get(attributeId))); } } writer.newLine(); } } } }
From source file:eu.itesla_project.eurostag.EurostagImpactAnalysis.java
private static void dumpBusesDictionary(Network network, EurostagDictionary dictionary, Path dir) throws IOException { try (BufferedWriter os = Files.newBufferedWriter(dir.resolve("dict_buses.csv"), StandardCharsets.UTF_8)) { for (Bus bus : Identifiables.sort(network.getBusBreakerView().getBuses())) { os.write(bus.getId() + ";" + dictionary.getEsgId(bus.getId())); os.newLine();//from w w w . ja v a 2 s . c o m } } }