@Override public boolean apply(Path input) { return Files.isRegularFile(input, optionsCopy); }
@Override public boolean apply(Path input) { return Files.isRegularFile(input, optionsCopy); }
@Override public boolean apply(Path input) { return Files.isRegularFile(input, optionsCopy); }
public boolean isRegularFile(Path path) { return Files.isRegularFile(path); }
/** * 判断是否为文件,如果file为null,则返回false * * @param path 文件 * @param isFollowLinks 是否跟踪软链(快捷方式) * @return 如果为文件true */ public static boolean isFile(Path path, boolean isFollowLinks) { if (null == path) { return false; } final LinkOption[] options = isFollowLinks ? new LinkOption[0] : new LinkOption[] { LinkOption.NOFOLLOW_LINKS }; return Files.isRegularFile(path, options); }
/** * 判断文件是否存在, from Jodd. * * @see {@link Files#exists} * @see {@link Files#isRegularFile} */ public static boolean isFileExists(Path path) { if (path == null) { return false; } return Files.exists(path) && Files.isRegularFile(path); }
private boolean isRegularFileAndReadable(Path path) { return path != null && Files.isRegularFile(path) && Files.isReadable(path); } }
static boolean isZip(Path path) { if (!Files.isRegularFile(path)) { return false; } try (ZipFile ignored = new ZipFile(path.toFile())) { return true; } catch (IOException ignored) { // Probably not a JAR file. return false; } }
@Override public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { if (!Files.isRegularFile(zip.getPath(file.toString()))) { Files.copy(file, zip.getPath(file.toString())); } return FileVisitResult.CONTINUE; } });
public Optional<JsonObject> loadFileToJson(Path configPath) { if (Files.isRegularFile(configPath)) { try (Reader reader = Files.newBufferedReader(configPath, TerasologyConstants.CHARSET)) { JsonElement userConfig = new JsonParser().parse(reader); if (userConfig.isJsonObject()) { return Optional.of(userConfig.getAsJsonObject()); } } catch (IOException e) { logger.error("Failed to load config file {}, falling back on default config", configPath); } } return Optional.empty(); }
@Override Collection<Path> getAllAssetDirs() { ArrayList<Path> paths = new ArrayList<>(); for (AssetPath assetPath : cppAssetManager.getAssetPaths()) { if (Files.isRegularFile(assetPath.file)) { paths.add(Fs.forJar(assetPath.file).getPath("assets")); } else { paths.add(assetPath.file); } } return paths; }
public static long zipAndCopyDir( File baseDir, OutputStream baseOutputStream, Progressable progressable ) throws IOException { long size = 0L; try (ZipOutputStream outputStream = new ZipOutputStream(baseOutputStream)) { List<String> filesToCopy = Arrays.asList(baseDir.list()); for (String fileName : filesToCopy) { final File fileToCopy = new File(baseDir, fileName); if (java.nio.file.Files.isRegularFile(fileToCopy.toPath())) { size += copyFileToZipStream(fileToCopy, outputStream, progressable); } else { log.warn("File at [%s] is not a regular file! skipping as part of zip", fileToCopy.getPath()); } } outputStream.flush(); } return size; }
protected EntityData.PlayerStore loadPlayerStoreData(String playerId) { Path storePath = storagePathProvider.getPlayerFilePath(playerId); if (Files.isRegularFile(storePath)) { try (InputStream inputStream = new BufferedInputStream(Files.newInputStream(storePath))) { return EntityData.PlayerStore.parseFrom(inputStream); } catch (IOException e) { logger.error("Failed to load player data for {}", playerId, e); } } return null; }
public static void checkWritableDirectory( Path directory ) throws FileSystemException { if ( !exists( directory ) ) { throw new NoSuchFileException( directory.toString() ); } if ( isRegularFile( directory ) ) { throw new FileSystemException( directory.toString() + ": Not a directory" ); } if ( !isWritable( directory ) ) { throw new AccessDeniedException( directory.toString() ); } }
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 public void loadGlobalStore() throws IOException { Path globalDataFile = storagePathProvider.getGlobalEntityStorePath(); if (Files.isRegularFile(globalDataFile)) { try (InputStream in = new BufferedInputStream(Files.newInputStream(globalDataFile))) { EntityData.GlobalStore store = EntityData.GlobalStore.parseFrom(in); GlobalStoreLoader loader = new GlobalStoreLoader(environment, entityManager, prefabSerializer); loader.load(store); } } }
@Test public void tryLock() { Path lockFilePath = worDir.toPath().resolve(DirectoryLock.LOCK_FILE_NAME); lock.tryLock(); assertThat(Files.exists(lockFilePath)).isTrue(); assertThat(Files.isRegularFile(lockFilePath)).isTrue(); lock.stop(); assertThat(Files.exists(lockFilePath)).isTrue(); }
public void testCreateParentDirectories_nonDirectoryParentExists() throws IOException { Path parent = createTempFile(); assertTrue(Files.isRegularFile(parent)); Path file = parent.resolve("foo"); try { MoreFiles.createParentDirectories(file); fail(); } catch (IOException expected) { } }
public void testDeleteRecursively_nonDirectoryFile() throws IOException { try (FileSystem fs = newTestFileSystem(SECURE_DIRECTORY_STREAM)) { Path file = fs.getPath("dir/a"); assertTrue(Files.isRegularFile(file, NOFOLLOW_LINKS)); MoreFiles.deleteRecursively(file); assertFalse(Files.exists(file, NOFOLLOW_LINKS)); Path symlink = fs.getPath("/symlinktodir"); assertTrue(Files.isSymbolicLink(symlink)); Path realSymlinkTarget = symlink.toRealPath(); assertTrue(Files.isDirectory(realSymlinkTarget, NOFOLLOW_LINKS)); MoreFiles.deleteRecursively(symlink); assertFalse(Files.exists(symlink, NOFOLLOW_LINKS)); assertTrue(Files.isDirectory(realSymlinkTarget, NOFOLLOW_LINKS)); } }
@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. }