Exemplo n.º 1
0
 /**
  * Ensures configured directory {@code path} exists.
  *
  * @throws IOException if {@code path} exists, but is not a directory, not accessible, or broken
  *     symbolic link.
  */
 static void ensureDirectoryExists(Path path) throws IOException {
   // this isn't atomic, but neither is createDirectories.
   if (Files.isDirectory(path)) {
     // verify access, following links (throws exception if something is wrong)
     // we only check READ as a sanity test
     path.getFileSystem().provider().checkAccess(path.toRealPath(), AccessMode.READ);
   } else {
     // doesn't exist, or not a directory
     try {
       Files.createDirectories(path);
     } catch (FileAlreadyExistsException e) {
       // convert optional specific exception so the context is clear
       IOException e2 = new NotDirectoryException(path.toString());
       e2.addSuppressed(e);
       throw e2;
     }
   }
 }