List of usage examples for java.nio.file Path getParent
Path getParent();
From source file:org.fao.geonet.api.records.formatters.AbstractFormatService.java
protected static boolean containsFile(Path container, Path desiredFile) throws IOException { if (!Files.exists(desiredFile) || !Files.exists(container)) { return false; }/* www. j a v a2 s . co m*/ Path canonicalDesired = desiredFile.toRealPath(); final Path canonicalContainer = container.toRealPath(); while (canonicalDesired.getParent() != null && !canonicalDesired.getParent().equals(canonicalContainer)) { canonicalDesired = canonicalDesired.getParent(); } return canonicalContainer.equals(canonicalDesired.getParent()); }
From source file:org.hara.sodra.utils.SodraUtils.java
public static final void createSolrCoreDirs(Path solrHome, String indexName) throws IOException { Path corePath = getSolrCorePath(solrHome, indexName); Files.createDirectory(corePath); Path coreConfPath = Paths.get(corePath.toString(), "conf"); Path baseConfPath = Paths.get(solrHome.getParent().toString(), "index_template_config", "conf"); copySolrConfigs(baseConfPath, coreConfPath); }
From source file:com.ibm.streamsx.topology.internal.context.remote.ZippedToolkitRemoteContext.java
private static Path pack(final Path folder, JsonObject graph, String tkName) throws IOException, URISyntaxException { String namespace = splAppNamespace(graph); String name = splAppName(graph); Path zipFilePath = Paths.get(folder.toAbsolutePath().toString() + ".zip"); String workingDir = zipFilePath.getParent().toString(); Path topologyToolkit = TkInfo.getTopologyToolkitRoot().getAbsoluteFile().toPath(); // Paths to copy into the toolkit Map<Path, String> paths = new HashMap<>(); // tkManifest is the list of toolkits contained in the archive try (PrintWriter tkManifest = new PrintWriter("manifest_tk.txt", "UTF-8")) { tkManifest.println(tkName);/*from w w w.j a va 2 s . co m*/ tkManifest.println("com.ibm.streamsx.topology"); JsonObject configSpl = object(graph, CONFIG, "spl"); if (configSpl != null) { objectArray(configSpl, "toolkits", tk -> { File tkRoot = new File(jstring(tk, "root")); String tkRootName = tkRoot.getName(); tkManifest.println(tkRootName); paths.put(tkRoot.toPath(), tkRootName); }); } } // mainComposite is a string of the namespace and the main composite. // This is used by the Makefile try (PrintWriter mainComposite = new PrintWriter("main_composite.txt", "UTF-8")) { mainComposite.print(namespace + "::" + name); } Path manifest = Paths.get(workingDir, "manifest_tk.txt"); Path mainComp = Paths.get(workingDir, "main_composite.txt"); Path makefile = topologyToolkit .resolve(Paths.get("opt", "python", "templates", "common", "Makefile.template")); paths.put(topologyToolkit, topologyToolkit.getFileName().toString()); paths.put(manifest, "manifest_tk.txt"); paths.put(mainComp, "main_composite.txt"); paths.put(makefile, "Makefile"); paths.put(folder, folder.getFileName().toString()); addAllToZippedArchive(paths, zipFilePath); manifest.toFile().delete(); mainComp.toFile().delete(); return zipFilePath; }
From source file:Main.java
public static void printDetails(Path p) { System.out.println("Details for path: " + p); int count = p.getNameCount(); System.out.println("Name count: " + count); for (int i = 0; i < count; i++) { Path name = p.getName(i); System.out.println("Name at index " + i + " is " + name); }//from w w w .j av a2s. c o m Path parent = p.getParent(); Path root = p.getRoot(); Path fileName = p.getFileName(); System.out.println("Parent: " + parent + ", Root: " + root + ", File Name: " + fileName); System.out.println("Absolute Path: " + p.isAbsolute()); }
From source file:org.ballerinalang.ballerina.openapi.convertor.service.OpenApiConverterUtils.java
/** * Write content to a file./* w w w . ja v a 2s . co m*/ * * @param path Path of the file. * @param content The content. * @throws IOException Error when creating or writing the file. */ private static void writeFile(Path path, String content) throws IOException { Path parentPath = path.getParent(); if (null != parentPath && Files.exists(parentPath)) { Files.createDirectories(parentPath); } Files.deleteIfExists(path); Files.createFile(path); try (PrintWriter writer = new PrintWriter(path.toString(), "UTF-8")) { writer.print(content); } }
From source file:org.jmingo.query.watch.QuerySetWatchService.java
private static Path getParentIfFile(Path path) { if (Files.isRegularFile(path)) { return path.getParent(); }/* ww w .j av a2 s. c om*/ return path; }
From source file:com.fizzed.stork.deploy.Archive.java
static private void unpackEntry(ArchiveInputStream ais, Path target) throws IOException { // always make sure parent dir exists Files.createDirectories(target.getParent()); try (OutputStream os = Files.newOutputStream(target, StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING)) { try (BufferedOutputStream bos = new BufferedOutputStream(os)) { int len = 0; byte[] BUFFER = new byte[1024]; while ((len = ais.read(BUFFER)) != -1) { bos.write(BUFFER, 0, len); }/*from w ww .j av a 2 s . c om*/ } } }
From source file:org.cryptomator.ui.logging.ConfigurableFileAppender.java
@PluginFactory public static AbstractAppender createAppender(@PluginAttribute("name") final String name, @PluginAttribute("pathPropertyName") final String pathPropertyName, @PluginAttribute("append") final String append, @PluginElement("Layout") Layout<? extends Serializable> layout) { if (name == null) { LOGGER.error("No name provided for HomeDirectoryAwareFileAppender"); return null; }// w w w . ja v a2s. c o m if (pathPropertyName == null) { LOGGER.error("No pathPropertyName provided for HomeDirectoryAwareFileAppender with name " + name); return null; } final String fileName = System.getProperty(pathPropertyName); if (Strings.isEmpty(fileName)) { LOGGER.warn("No log file location provided in system property \"" + pathPropertyName + "\""); return null; } final Path filePath = parsePath(fileName); if (filePath == null) { LOGGER.warn("Invalid path \"" + fileName + "\""); return null; } if (!Files.exists(filePath.getParent())) { try { Files.createDirectories(filePath.getParent()); } catch (IOException e) { LOGGER.error("Could not create parent directories for log file located at " + filePath.toString(), e); return null; } } final boolean shouldAppend = Booleans.parseBoolean(append, true); if (layout == null) { layout = PatternLayout.createDefaultLayout(); } final FileManager manager = FileManager.getFileManager(filePath.toString(), shouldAppend, false, true, null, layout, DEFAULT_BUFFER_SIZE); return new ConfigurableFileAppender(name, layout, null, manager); }
From source file:org.sakuli.actions.screenbased.ScreenshotActions.java
/** * Transfers a {@link BufferedImage} to an picture and saves it * * @param pictureFile Path to the final image * @return {@link Path} ot the screenshot. *///from w ww . j a va2 s. c om static Path createPictureFromBufferedImage(Path pictureFile, String screenshotFormat, BufferedImage bufferedImage) throws IOException { Path absPath = pictureFile.normalize().toAbsolutePath(); //check Folder if (!Files.exists(absPath.getParent())) { Files.createDirectory(absPath.getParent()); } if (Files.exists(absPath)) { LOGGER.info("overwrite screenshot '{}'", absPath); Files.delete(absPath); } Files.createFile(pictureFile); OutputStream outputStream = Files.newOutputStream(pictureFile); if (!allowedScreenshotFormats.contains(screenshotFormat)) { throw new IOException("Format '" + screenshotFormat + "' is not supported! Use " + allowedScreenshotFormats.toString()); } //write image ImageIO.write(bufferedImage, screenshotFormat, outputStream); LOGGER.info("screen shot saved to file \"" + pictureFile.toFile().getAbsolutePath() + "\""); return pictureFile; }
From source file:api.wiki.WikiGenerator.java
private static void writePage(Path page, String markup) throws IOException { Files.createDirectories(page.getParent()); Files.write(page, markup.getBytes(UTF_8), CREATE, TRUNCATE_EXISTING); }