@Test public void will_fail_if_unable_to_create_the_directory_for_permission_or_other_reasons() throws IOException { assumeTrue("this test works only on POSIX compatible file systems", Files.getFileAttributeView(baseDir, PosixFileAttributeView.class) != null); Set<PosixFilePermission> noPermissions = new HashSet<>(); Files.setPosixFilePermissions(baseDir, noPermissions); assertThat("the file system did not let us change file permissions", Files.getPosixFilePermissions(baseDir), is(noPermissions)); thrown.expect(AccessDeniedException.class); UniqueDirectories.createUniqueDir(baseDir, 123); }
public static Path createUniqueDir(Path parentDir, long sequence) throws IOException { Files.createDirectories(parentDir); while (true) { Path path = parentDir.resolve(Long.toString(sequence)); try { return Files.createDirectory(path); } catch (FileAlreadyExistsException e) { sequence++; } } }
UniqueDirectories { public static Path createUniqueDir(Path parentDir, long sequence) throws IOException { Files.createDirectories(parentDir); while (true) { Path path = parentDir.resolve(Long.toString(sequence)); try { return Files.createDirectory(path); } catch (FileAlreadyExistsException e) { sequence++; } } } }
UniqueDirectories { public static Path createUniqueDir(Path parentDir, long sequence) throws IOException { Files.createDirectories(parentDir); while (true) { Path path = parentDir.resolve(Long.toString(sequence)); try { return Files.createDirectory(path); } catch (FileAlreadyExistsException e) { sequence++; } } }  }
UniqueDirectories { public static Path createUniqueDir(Path parentDir, long sequence) throws IOException { Files.createDirectories(parentDir); while (true) { Path path = parentDir.resolve(Long.toString(sequence)); try { return Files.createDirectory(path); } catch (FileAlreadyExistsException e) { sequence++; } } }  static Path createUniqueDir(Path parentDir, long sequence); }
UniqueDirectories { public static Path createUniqueDir(Path parentDir, long sequence) throws IOException { Files.createDirectories(parentDir); while (true) { Path path = parentDir.resolve(Long.toString(sequence)); try { return Files.createDirectory(path); } catch (FileAlreadyExistsException e) { sequence++; } } }  static Path createUniqueDir(Path parentDir, long sequence);  }