code: @Override
  	public RefCountedFile apply(File file) throws IOException {
  		final File directory = tempDirectories[nextIndex()];
  
  		while (true) {
  			try {
  				if (file == null) {
  					final File newFile = new File(directory, ".tmp_" + UUID.randomUUID());
  					final OutputStream out = Files.newOutputStream(newFile.toPath(), StandardOpenOption.CREATE_NEW);
  					return RefCountedFile.newFile(newFile, out);
  				} else {
  					final OutputStream out = Files.newOutputStream(file.toPath(), StandardOpenOption.APPEND);
  					return RefCountedFile.restoredFile(file, out, file.length());
  				}
  			} catch (FileAlreadyExistsException ignored) {
  				// fall through the loop and retry
  			}
  		}
  	}
docs: Gets the next temp file and stream to temp file.
  This creates the temp file atomically, making sure no previous file is overwritten.
  
  <p>This method is safe against concurrent use.
  
  @return A pair of temp file and output stream to that temp file.
  @throws IOException Thrown, if the stream to the temp file could not be opened.