예제 #1
0
  /**
   * Checks the given {@link Path} against the given tests.
   *
   * <p>The available tests are:
   *
   * <table>
   *   <tr><th>d</th><td>Test if the path is a directory.</td></tr>
   *   <tr><th>e</th><td>Test if the path exists.</td></tr>
   *   <tr><th>f</th><td>Test if the path is a regular file.</td></tr>
   *   <tr><th>r</th><td>Test if the path is readable.</td></tr>
   *   <tr><th>s</th><td>Test if the path is a non-zero-length file.</td></tr>
   *   <tr><th>w</th><td>Test if the path is writable.</td></tr>
   *   <tr><th>x</th><td>Test if the path is executable or usable.</td></tr>
   *   <tr><th>z</th><td>Test if the path is a zero length file.</td></tr>
   * </table>
   *
   * @param path The {@code Path} to check.
   * @param tests The set of tests to run.
   * @return {@code false} if any test fails, otherwise {@code true}.
   * @see #testPath(Path, char)
   */
  public static boolean check(final Path path, final CharSequence tests) {
    for (int i = 0; i < tests.length(); i++) {
      FileSystemTestFailure failure = FileSystemTools.testPath(path, tests.charAt(i));
      if (failure != null) return false;
    }

    return true;
  }
예제 #2
0
 /**
  * Checks the given {@link Path} against the given tests. Unlike {@link #check(Path,
  * CharSequence)}, a test failure will throw an {@link FileSystemTestFailure}.
  *
  * @param path The {@code Path} to check.
  * @param tests The set of tests to run.
  * @see #testPath(Path, char)
  * @throws FileSystemTestFailure If any of the tests fail.
  */
 public static void require(final Path path, final CharSequence tests) {
   for (int i = 0; i < tests.length(); i++) {
     FileSystemTestFailure failure = FileSystemTools.testPath(path, tests.charAt(i));
     if (failure != null) throw failure;
   }
 }