public boolean notExists(Path path, LinkOption... options) { return Files.notExists(path, options); }
public boolean notExists(Path path, LinkOption... options) { return Files.notExists(path, options); }
private void createDirectoryIfNorExist(Path path) throws IOException { if (Files.notExists(path)) { Files.createDirectory(path); } }
private void createDirectoryIfNorExist(Path path) throws IOException { if (Files.notExists(path)) { Files.createDirectory(path); } }
private boolean isValidResultsDirectory(final Path resultsDirectory) { if (Files.notExists(resultsDirectory)) { LOGGER.warn("{} does not exists", resultsDirectory); return false; } if (!Files.isDirectory(resultsDirectory)) { LOGGER.warn("{} is not a directory", resultsDirectory); return false; } return true; } }
/** Writes this to {@code directory} as UTF-8 using the standard directory structure. */ public void writeTo(Path directory) throws IOException { checkArgument(Files.notExists(directory) || Files.isDirectory(directory), "path %s exists but is not a directory.", directory); Path outputDirectory = directory; if (!packageName.isEmpty()) { for (String packageComponent : packageName.split("\\.")) { outputDirectory = outputDirectory.resolve(packageComponent); } Files.createDirectories(outputDirectory); } Path outputPath = outputDirectory.resolve(typeSpec.name + ".java"); try (Writer writer = new OutputStreamWriter(Files.newOutputStream(outputPath), UTF_8)) { writeTo(writer); } }
@Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { final Path dirToCreate = zipFileSystem.getPath(root.toString(), dir.toString()); if(Files.notExists(dirToCreate)){ if(logger.isDebugEnabled()) logger.debug("Creating directory %s\n", dirToCreate); Files.createDirectories(dirToCreate); } return FileVisitResult.CONTINUE; } });
@Override public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { final Path dirToCreate = Paths.get(destDir.toString(), dir.toString()); if(Files.notExists(dirToCreate)){ if(logger.isDebugEnabled()) logger.debug("Creating directory %s", dirToCreate); Files.createDirectory(dirToCreate); } return FileVisitResult.CONTINUE; } });
private String repositoryReader(Path filePath) { String content = null; if(Files.notExists(filePath) || !Files.isReadable(filePath)){ log.warn("Error reading the file: " + filePath + " - Does not exist or is not readable. continuing..."); return null; } try { content = new String(Files.readAllBytes(filePath)); } catch (IOException e) { log.error("Error reading the file: " + filePath + " message: " + e.getMessage(), e); } return content; }
private String configReader(Path filePath) { String content = null; if(Files.notExists(filePath) || !Files.isReadable(filePath)){ log.warn("Error reading the file: " + filePath + " - Does not exist or is not readable. continuing..."); return null; } try { content = new String(Files.readAllBytes(filePath)); } catch (IOException e) { log.error("Error reading the file: " + filePath + " message: " + e.getMessage(), e); } return content; }
@Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { if (Files.notExists(file)) { return FileVisitResult.CONTINUE; } final Path dest = outputDirectory.resolve(sourceDirectory.relativize(file)); try { Files.copy(file, dest, StandardCopyOption.REPLACE_EXISTING); } catch (IOException e) { LOGGER.error("Could not copy file", e); } return FileVisitResult.CONTINUE; } }
private String repositoryReader(Path filePath) { String content = null; if(Files.notExists(filePath) || !Files.isReadable(filePath)){ log.warn("Error reading the file: " + filePath + " - Does not exist or is not readable. continuing..."); return null; } try { content = new String(Files.readAllBytes(filePath)); } catch (IOException e) { log.error("Error reading the file: " + filePath + " message: " + e.getMessage(), e); } return content; } }
public static boolean createFile(final Path path) { try { final Path parent = path.getParent(); if (parent == null) { log.warn("Failed to create file as the parent was null. path: {}", path); return false; } Files.createDirectories(parent); if (Files.notExists(path)) { Files.createFile(path); } return true; } catch (final Exception e) { log.warn("createFile failed, path: {}", path, e); return false; } }
@Override public final byte[] put(String key, byte[] value) { // Make sure the directory exists. byte[] data = get(key); if (!Arrays.equals(data, value)) try { if (Files.notExists(cacheDirectory)) { Files.createDirectories(cacheDirectory); } Path file = cacheDirectory.resolve(key); Files.write(file, value); } catch (IOException e) { throw new UncheckedIOException(e); } return data; }
private Optional<PluginConfiguration> loadPluginConfiguration(final Path pluginDirectory) { final Path configuration = pluginDirectory.resolve("allure-plugin.yml"); if (Files.notExists(configuration)) { LOGGER.warn("Invalid plugin directory " + pluginDirectory); return Optional.empty(); } final ObjectMapper mapper = new ObjectMapper(new YAMLFactory()); try (InputStream is = Files.newInputStream(configuration)) { return Optional.of(mapper.readValue(is, PluginConfiguration.class)); } catch (IOException e) { LOGGER.error("Could not read plugin configuration: {}", e); return Optional.empty(); } }
/** * Get banner text * * @return return blade start banner text */ public String bannerText() { if (null != bannerText) return bannerText; String bannerPath = environment.get(ENV_KEY_BANNER_PATH, null); if (StringKit.isEmpty(bannerPath) || Files.notExists(Paths.get(bannerPath))) { return null; } try { BufferedReader bufferedReader = Files.newBufferedReader(Paths.get(bannerPath)); bannerText = bufferedReader.lines().collect(Collectors.joining("\r\n")); } catch (Exception e) { log.error("Load Start Banner file error", e); } return bannerText; }
/** * Get banner text * * @return return blade start banner text */ public String bannerText() { if (null != bannerText) return bannerText; String bannerPath = environment.get(ENV_KEY_BANNER_PATH, null); if (StringKit.isEmpty(bannerPath) || Files.notExists(Paths.get(bannerPath))) { return null; } try { BufferedReader bufferedReader = Files.newBufferedReader(Paths.get(bannerPath)); bannerText = bufferedReader.lines().collect(Collectors.joining("\r\n")); } catch (Exception e) { log.error("Load Start Banner file error", e); } return bannerText; }
private void addConfigFileToBackup(URL fileUrl) throws IOException { if (fileUrl == null) { return; } try { Path source = getSource(fileUrl); if (Files.notExists(source)) { return; } Path destination = configDirectory.resolve(source.getFileName()); Files.copy(source, destination, StandardCopyOption.COPY_ATTRIBUTES); backupDefinition.addConfigFileToBackup(destination); } catch (URISyntaxException e) { throw new IOException(e); } }
/** * Creates a Swagger2MarkupConverter.Builder using a local Path. * * @param swaggerPath the local Path * @return a Swagger2MarkupConverter */ public static Builder from(Path swaggerPath) { Validate.notNull(swaggerPath, "swaggerPath must not be null"); if (Files.notExists(swaggerPath)) { throw new IllegalArgumentException(String.format("swaggerPath does not exist: %s", swaggerPath)); } try { if (Files.isHidden(swaggerPath)) { throw new IllegalArgumentException("swaggerPath must not be a hidden file"); } } catch (IOException e) { throw new RuntimeException("Failed to check if swaggerPath is a hidden file", e); } return new Builder(swaggerPath); }
@Test public void shouldHonorSuiteName() throws IOException { Path outputDirectory = TestHelper.createRandomDirectory(); TestNG tng = create(outputDirectory, SampleA.class, SampleB.class); tng.addListener(new TestHTMLReporter()); Path fileA = outputDirectory.resolve("SuiteA-JDK5"); Path fileB = outputDirectory.resolve("SuiteB-JDK5"); Assert.assertTrue(Files.notExists(fileA)); Assert.assertTrue(Files.notExists(fileB)); tng.run(); Assert.assertTrue(Files.exists(fileA)); Assert.assertTrue(Files.exists(fileB)); }