java.nio.file.Files.isRegularFile()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.4k)|赞(0)|评价(0)|浏览(1261)

本文整理了Java中java.nio.file.Files.isRegularFile()方法的一些代码示例,展示了Files.isRegularFile()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Files.isRegularFile()方法的具体详情如下:
包路径:java.nio.file.Files
类名称:Files
方法名:isRegularFile

Files.isRegularFile介绍

暂无

代码示例

代码示例来源:origin: google/guava

@Override
public boolean apply(Path input) {
 return Files.isRegularFile(input, optionsCopy);
}

代码示例来源:origin: prestodb/presto

@Override
public boolean apply(Path input) {
 return Files.isRegularFile(input, optionsCopy);
}

代码示例来源:origin: google/j2objc

@Override
public boolean apply(Path input) {
 return Files.isRegularFile(input, optionsCopy);
}

代码示例来源:origin: org.assertj/assertj-core

public boolean isRegularFile(Path path) {
 return Files.isRegularFile(path);
}

代码示例来源:origin: looly/hutool

/**
 * 判断是否为文件,如果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);
}

代码示例来源:origin: springside/springside4

/**
 * 判断文件是否存在, 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);
}

代码示例来源:origin: Graylog2/graylog2-server

private boolean isRegularFileAndReadable(Path path) {
    return path != null && Files.isRegularFile(path) && Files.isReadable(path);
  }
}

代码示例来源:origin: line/armeria

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;
  }
}

代码示例来源:origin: MovingBlocks/Terasology

@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;
  }
});

代码示例来源:origin: MovingBlocks/Terasology

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();
}

代码示例来源:origin: robolectric/robolectric

@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;
}

代码示例来源:origin: apache/incubator-druid

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;
}

代码示例来源:origin: MovingBlocks/Terasology

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;
}

代码示例来源:origin: neo4j/neo4j

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() );
  }
}

代码示例来源:origin: Graylog2/graylog2-server

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);
}

代码示例来源:origin: MovingBlocks/Terasology

@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);
    }
  }
}

代码示例来源:origin: SonarSource/sonarqube

@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();
}

代码示例来源:origin: google/guava

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) {
 }
}

代码示例来源:origin: google/guava

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));
 }
}

代码示例来源:origin: azkaban/azkaban

@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.
}

相关文章

微信公众号

最新文章

更多