/** * This implementation checks whether the underlying file is marked as readable * (and corresponds to an actual file with content, not to a directory). * @see java.nio.file.Files#isReadable(Path) * @see java.nio.file.Files#isDirectory(Path, java.nio.file.LinkOption...) */ @Override public boolean isReadable() { return (Files.isReadable(this.path) && !Files.isDirectory(this.path)); }
public boolean isReadable(Path path) { return Files.isReadable(path); }
/** * This implementation checks whether the underlying file is marked as readable * (and corresponds to an actual file with content, not to a directory). * @see java.io.File#canRead() * @see java.io.File#isDirectory() */ @Override public boolean isReadable() { return (this.file != null ? this.file.canRead() && !this.file.isDirectory() : Files.isReadable(this.filePath) && !Files.isDirectory(this.filePath)); }
/** * This implementation checks whether the underlying file is marked as readable * (and corresponds to an actual file with content, not to a directory). * @see java.nio.file.Files#isReadable(Path) * @see java.nio.file.Files#isDirectory(Path, java.nio.file.LinkOption...) */ @Override public boolean isReadable() { return (Files.isReadable(this.path) && !Files.isDirectory(this.path)); }
private boolean isRegularFileAndReadable(Path path) { return path != null && Files.isRegularFile(path) && Files.isReadable(path); } }
/** * This implementation checks whether the underlying file is marked as readable * (and corresponds to an actual file with content, not to a directory). * @see java.io.File#canRead() * @see java.io.File#isDirectory() */ @Override public boolean isReadable() { return (this.file != null ? this.file.canRead() && !this.file.isDirectory() : Files.isReadable(this.filePath) && !Files.isDirectory(this.filePath)); }
public KerberosAuthentication(String principal, String keytabLocation) { requireNonNull(principal, "principal is null"); requireNonNull(keytabLocation, "keytabLocation is null"); Path keytabPath = Paths.get(keytabLocation); checkArgument(exists(keytabPath), "keytab does not exist: " + keytabLocation); checkArgument(isReadable(keytabPath), "keytab is not readable: " + keytabLocation); this.principal = createKerberosPrincipal(principal); this.configuration = createConfiguration(this.principal.getName(), keytabLocation); }
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; }
/** * 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); }
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 <T> T parseJson(Path path, Class<T> javaType) { if (!path.isAbsolute()) { path = path.toAbsolutePath(); } checkArgument(exists(path), "File does not exist: %s", path); checkArgument(isReadable(path), "File is not readable: %s", path); try { byte[] json = Files.readAllBytes(path); ObjectMapper mapper = new ObjectMapperProvider().get() .enable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); return mapper.readValue(json, javaType); } catch (IOException e) { throw new IllegalArgumentException(format("Invalid JSON file '%s' for '%s'", path, javaType), e); } } }
/** * Checks if a storage directory path is accessible. * * @param path the given path * @return true if path exists, false otherwise */ public static boolean isStorageDirAccessible(String path) { Path filePath = Paths.get(path); return Files.exists(filePath) && Files.isReadable(filePath) && Files.isWritable(filePath) && Files.isExecutable(filePath); }
@Override public Optional<Multimap<String, String>> validate() { final ArrayListMultimap<String, String> errors = ArrayListMultimap.create(); final Path path = Paths.get(path()); if (!Files.exists(path)) { errors.put("path", "The file does not exist."); } else if (!Files.isReadable(path)) { errors.put("path", "The file cannot be read."); } return errors.isEmpty() ? Optional.empty() : Optional.of(errors); }
@Override public Optional<Multimap<String, String>> validate() { final ArrayListMultimap<String, String> errors = ArrayListMultimap.create(); final Path path = Paths.get(path()); if (!Files.exists(path)) { errors.put("path", "The file does not exist."); } else if (!Files.isReadable(path)) { errors.put("path", "The file cannot be read."); } return errors.isEmpty() ? Optional.empty() : Optional.of(errors); }
public static void checkPath(String keystoreFilePath, String fileNameLogOnly) { if (keystoreFilePath == null || keystoreFilePath.length() == 0) { throw new ElasticsearchException("Empty file path for "+fileNameLogOnly); } if (Files.isDirectory(Paths.get(keystoreFilePath), LinkOption.NOFOLLOW_LINKS)) { throw new ElasticsearchException("Is a directory: " + keystoreFilePath+" Expected a file for "+fileNameLogOnly); } if(!Files.isReadable(Paths.get(keystoreFilePath))) { throw new ElasticsearchException("Unable to read " + keystoreFilePath + " ("+Paths.get(keystoreFilePath)+"). Please make sure this files exists and is readable regarding to permissions. Property: "+fileNameLogOnly); } }
/** * Set permission of log file so that logviewer can serve the file. * * @param fileName log file */ public void setLogFilePermission(String fileName) throws IOException { File file = new File(logRootDir, fileName).getCanonicalFile(); boolean runAsUser = ObjectReader.getBoolean(stormConf.get(SUPERVISOR_RUN_WORKER_AS_USER), false); File parent = new File(logRootDir, fileName).getParentFile(); Optional<File> mdFile = (parent == null) ? Optional.empty() : getMetadataFileForWorkerLogDir(parent); Optional<String> topoOwner = mdFile.isPresent() ? Optional.of(getTopologyOwnerFromMetadataFile(mdFile.get().getCanonicalPath())) : Optional.empty(); if (runAsUser && topoOwner.isPresent() && file.exists() && !Files.isReadable(file.toPath())) { LOG.debug("Setting permissions on file {} with topo-owner {}", fileName, topoOwner); try { ClientSupervisorUtils.processLauncherAndWait(stormConf, topoOwner.get(), Lists.newArrayList("blob", file.getCanonicalPath()), null, "setup group read permissions for file: " + fileName); } catch (IOException e) { numSetPermissionsExceptions.mark(); throw e; } } }
private SSLEngineConfigurator buildSslEngineConfigurator(Path certFile, Path keyFile, String keyPassword) throws GeneralSecurityException, IOException { if (keyFile == null || !Files.isRegularFile(keyFile) || !Files.isReadable(keyFile)) { throw new InvalidKeyException("Unreadable or missing private key: " + keyFile); } if (certFile == null || !Files.isRegularFile(certFile) || !Files.isReadable(certFile)) { throw new CertificateException("Unreadable or missing X.509 certificate: " + certFile); } final SSLContextConfigurator sslContextConfigurator = new SSLContextConfigurator(); final char[] password = firstNonNull(keyPassword, "").toCharArray(); final KeyStore keyStore = PemKeyStore.buildKeyStore(certFile, keyFile, password); sslContextConfigurator.setKeyStorePass(password); sslContextConfigurator.setKeyStoreBytes(KeyStoreUtils.getBytes(keyStore, password)); final SSLContext sslContext = sslContextConfigurator.createSSLContext(true); return new SSLEngineConfigurator(sslContext, false, false, false); }
@Override protected void doStart() throws Exception { Path path = Paths.get(config.path()); fileInfo = FileInfo.forPath(path); if (!Files.isReadable(path)) { LOG.warn("Cannot read database file {}", config.path()); setError(new IllegalStateException("Cannot read database file " + config.path())); } else { try { this.databaseReader.set(loadReader(path.toFile())); } catch (Exception e) { LOG.warn("Unable to read data base file {}", config.path()); setError(e); } } }
@Test public void canReadMemInfoFileIfExists() { final long size = this.util.getOsTotalFreeMemorySize(); final Path memFile = Paths.get("/proc/meminfo"); if (!(Files.isRegularFile(memFile) && Files.isReadable(memFile))) { assertTrue(size == 0); } // todo HappyRay: investigate why size returned is 0 on Travis only but works on my Linux machine. // I can't find a way to get to the Gradle test report on Travis which makes debugging difficult. }