List of usage examples for java.nio.file Path getParent
Path getParent();
From source file:com.facebook.buck.util.unarchive.Unzip.java
private static boolean isTopLevel(Path path, SortedMap<Path, ZipArchiveEntry> pathMap) { for (Path p = path.getParent(); p != null; p = p.getParent()) { if (pathMap.containsKey(p)) { return false; }//from w w w. j a va2 s . c o m } return true; }
From source file:com.facebook.buck.util.unarchive.Unzip.java
private static void fillIntermediatePaths(Path path, SortedMap<Path, ZipArchiveEntry> pathMap) { for (Path p = path.getParent(); p != null; p = p.getParent()) { if (pathMap.containsKey(p)) { break; }//w w w. j a v a2s . c o m pathMap.put(p, new ZipArchiveEntry(p + "/")); } }
From source file:org.apache.nifi.minifi.bootstrap.configuration.ingestors.FileChangeIngestor.java
protected static WatchService initializeWatcher(Path filePath) { try {//from www . j a va 2 s. com final WatchService fsWatcher = FileSystems.getDefault().newWatchService(); final Path watchDirectory = filePath.getParent(); watchDirectory.register(fsWatcher, ENTRY_MODIFY); return fsWatcher; } catch (IOException ioe) { throw new IllegalStateException("Unable to initialize a file system watcher for the path " + filePath, ioe); } }
From source file:edu.stanford.slac.archiverappliance.PlainPB.PlainPBFileNameUtilityTest.java
private static void mkPath(Path nf) throws IOException { if (!Files.exists(nf)) { Files.createDirectories(nf.getParent()); Files.createFile(nf);/*from w w w . j av a 2 s . c o m*/ } }
From source file:org.opencb.opencga.storage.core.variant.VariantStorageBaseTest.java
public static URI getResourceUri(String resourceName) throws IOException { Path rootDir = getTmpRootDir(); Path resourcePath = rootDir.resolve(resourceName); if (!resourcePath.getParent().toFile().exists()) { Files.createDirectory(resourcePath.getParent()); }// w w w . j a va 2 s .co m if (!resourcePath.toFile().exists()) { Files.copy(VariantStorageManagerTest.class.getClassLoader().getResourceAsStream(resourceName), resourcePath, StandardCopyOption.REPLACE_EXISTING); } return resourcePath.toUri(); }
From source file:divconq.util.IOUtil.java
public static boolean saveEntireFile2(Path dest, String content) { try {/*from ww w . j a v a 2s . c o m*/ Files.createDirectories(dest.getParent()); Files.write(dest, Utf8Encoder.encode(content), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE, StandardOpenOption.SYNC); } catch (Exception x) { return false; } return true; }
From source file:divconq.util.IOUtil.java
public static boolean saveEntireFile2(Path dest, Memory content) { try {/*from w w w . j a v a 2 s. c om*/ Files.createDirectories(dest.getParent()); Files.write(dest, content.toArray(), StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE, StandardOpenOption.SYNC); } catch (Exception x) { return false; } return true; }
From source file:com.github.jinahya.simple.file.back.LocalFileBackTest.java
@Test(enabled = true, invocationCount = 1) public static void leafPath() throws IOException, FileBackException { final Path rootPath = FileBackTests.randomRootPath(); final ByteBuffer fileKey = randomFileKey(); final Path leafPath = LocalFileBack.leafPath(rootPath, fileKey, true); assertTrue(Files.isDirectory(leafPath.getParent())); }
From source file:org.apache.cloudstack.storage.configdrive.ConfigDriveBuilder.java
/** * Writes a String encoded in base 64 to a file in the given folder. * The content will be decoded and then written to the file. Be aware that we will overwrite the content of the file if it already exists. * Moreover, the content will must be encoded in {@link StandardCharsets#US_ASCII} before it is encoded in base 64. *//* w w w . j a v a 2 s. c o m*/ public static File base64StringToFile(String encodedIsoData, String folder, String fileName) throws IOException { byte[] decoded = Base64.decodeBase64(encodedIsoData.getBytes(StandardCharsets.US_ASCII)); Path destPath = Paths.get(folder, fileName); try { Files.createDirectories(destPath.getParent()); } catch (final IOException e) { LOG.warn("Exception hit while trying to recreate directory: " + destPath.getParent().toString()); } return Files.write(destPath, decoded).toFile(); }
From source file:edu.jhu.hlt.concrete.stanford.ConcreteStanfordRunner.java
public static void prepareInputOutput(Path in, Path out) throws IOException { if (!Files.exists(in)) throw new IOException(in.toString() + " does not exist. Ensure it exists and re-run this program."); Optional<Path> outPath = Optional.ofNullable(out.getParent()); outPath.ifPresent(p -> {/*from ww w.j a va 2 s . co m*/ if (!Files.exists(p)) { LOGGER.debug("Attempting to create output directory: {}", outPath.toString()); try { Files.createDirectories(p); } catch (IOException e) { throw new UncheckedIOException(e); } } }); }