public static boolean isDirExists(Path dirPath) { return dirPath != null && Files.exists(dirPath) && Files.isDirectory(dirPath); }
@JsonCreator public LocalLoadSpec( @JacksonInject LocalDataSegmentPuller puller, @JsonProperty(value = "path", required = true) final String path ) { Preconditions.checkNotNull(path); this.path = Paths.get(path); Preconditions.checkArgument(Files.exists(Paths.get(path)), "[%s] does not exist", path); this.puller = puller; }
/** * Get Ignite Hadoop config directory. * * @param igniteHome Ignite home. * @return Ignite Hadoop config directory. */ private static File igniteHadoopConfig(String igniteHome) { Path path = Paths.get(igniteHome, "modules", "hadoop", "config"); if (!Files.exists(path)) path = Paths.get(igniteHome, "config", "hadoop"); if (Files.exists(path)) return path.toFile(); else return new File(igniteHome, "docs"); }
private void forEachTopologyDistDir(ConsumePathAndId consumer) throws IOException { Path stormCodeRoot = Paths.get(ConfigUtils.supervisorStormDistRoot(conf)); if (Files.exists(stormCodeRoot) && Files.isDirectory(stormCodeRoot)) { try (DirectoryStream<Path> children = Files.newDirectoryStream(stormCodeRoot)) { for (Path child : children) { if (Files.isDirectory(child)) { String topologyId = child.getFileName().toString(); consumer.accept(child, topologyId); } } } } }
private String determineDockerConfigPath() { String dockerConfigEnv = System.getenv(DOCKER_CONFIG_ENV); String dockerConfigProperty = System.getProperty(DOCKER_CONFIG_PROPERTY); Path dockerConfig = Paths.get(System.getProperty("user.home"), ".docker", "config.json"); if (dockerConfigEnv != null && !dockerConfigEnv.trim().isEmpty() && Files.exists(Paths.get(dockerConfigEnv))) { return dockerConfigEnv; } else if (dockerConfigProperty != null && !dockerConfigProperty.trim().isEmpty() && Files.exists(Paths.get(dockerConfigProperty))) { return dockerConfigProperty; } else if (Files.exists(dockerConfig)) { return dockerConfig.toString(); } else { return null; } }
static Collection<String> getLocalizedUsers(Path localBaseDir) throws IOException { Path userCacheDir = getUserCacheDir(localBaseDir); if (!Files.exists(userCacheDir)) { return Collections.emptyList(); } return Files.list(userCacheDir).map((p) -> p.getFileName().toString()).collect(Collectors.toList()); }
private PersistentAtomicReference(final Path filename, final JavaType javaType, final Supplier<? extends T> initialValue) throws IOException, InterruptedException { try { this.filename = filename.toAbsolutePath(); this.tempfilename = filename.getFileSystem().getPath(this.filename.toString() + ".tmp"); if (Files.exists(filename)) { final byte[] bytes = Files.readAllBytes(filename); if (bytes.length > 0) { value = Json.read(bytes, javaType); } else { value = initialValue.get(); } } else { value = initialValue.get(); } } catch (InterruptedIOException | ClosedByInterruptException e) { throw new InterruptedException(e.getMessage()); } }
@Test public void shouldRemoveDirectory() throws Exception { Path path = Paths.get(Testing.Files.dataDir(), "test-dir"); assertThat(path.toFile().mkdirs()).isTrue(); Path file = path.resolve("file.txt"); assertThat(file.toFile().createNewFile()).isTrue(); Testing.Files.delete(path); assertThat(java.nio.file.Files.exists(path)).isFalse(); } }
private static void appendToBootClassPath(Path libFolder) { Path bootLibs = libFolder.resolve("boot"); if (Files.exists(bootLibs)) { for (File f : bootLibs.toFile().listFiles()) { if (f.getName().toLowerCase().endsWith(".jar")) { try { if (isDebug()) { debugPrint("Adding " + f.getAbsolutePath() + " to bootstrap classpath"); } inst.appendToBootstrapClassLoaderSearch(new JarFile(f)); } catch (IOException e) { } } } } }
/** * Answers if the given path denotes existing directory. * * @param path The directory path. * @return {@code True} if the given path denotes an existing directory. */ public static boolean exists(String path) { if (F.isEmpty(path)) return false; Path p = Paths.get(path); return Files.exists(p) && Files.isDirectory(p) && Files.isReadable(p); }
@Test public void shouldNotThrowWhenOldRecordingLogsAreDeleted() throws IOException { createSegmentFile(recordingThreeId); final Path segmentFilePath = Paths.get(segmentFileName(recordingThreeId, 0)); final boolean segmentFileExists = Files.exists(archiveDir.toPath().resolve(segmentFilePath)); assumeThat(segmentFileExists, is(true)); final Catalog catalog = new Catalog(archiveDir, null, 0, MAX_ENTRIES, clock); catalog.close(); }
@VisibleForTesting static long localVersionOfBlob(Path versionFile) { long currentVersion = -1; if (Files.exists(versionFile) && !(Files.isDirectory(versionFile))) { try (BufferedReader br = new BufferedReader(new FileReader(versionFile.toFile()))) { String line = br.readLine(); currentVersion = Long.parseLong(line); } catch (IOException e) { throw new RuntimeException(e); } } return currentVersion; }
private JavaContainerBuilder addDirectory( Path directory, AbsoluteUnixPath destination, LayerType layerType, Predicate<Path> pathFilter) throws IOException { if (!Files.exists(directory)) { throw new NoSuchFileException(directory.toString()); } if (!Files.isDirectory(directory)) { throw new NotDirectoryException(directory.toString()); } layerConfigurationsBuilder.addDirectoryContents(layerType, directory, pathFilter, destination); classpath.add(destination.toString()); return this; } }
public RuleDocGenerator(FileWriter writer, Path root) { this.writer = Objects.requireNonNull(writer, "A file writer must be provided"); this.root = Objects.requireNonNull(root, "Root directory must be provided"); Path docsDir = root.resolve("docs"); if (!Files.exists(docsDir) || !Files.isDirectory(docsDir)) { throw new IllegalArgumentException("Couldn't find \"docs\" subdirectory"); } }
FileSystemHttpVfs(Path rootDir) { this.rootDir = requireNonNull(rootDir, "rootDir").toAbsolutePath(); if (!Files.exists(this.rootDir) || !Files.isDirectory(this.rootDir)) { throw new IllegalArgumentException("rootDir: " + rootDir + " (not a directory"); } }
/** * Copy file to working directory. * * @param filePath File path. * @return File name. * @throws IOException If coping failed. */ String copyToWorkDir(String filePath) throws IOException { Path srcFile = Paths.get(filePath); if (Files.exists(srcFile)) { checkDownloadFolder(); Path newDir = Paths.get(downloadFolder); Path fileName = srcFile.getFileName(); Files.copy(srcFile, newDir.resolve(fileName), StandardCopyOption.REPLACE_EXISTING); return fileName.toString(); } return null; }