code: public static File createHierarchicalTempFile(final File baseDirectory, final int pathElements, final String prefix, final String suffix) throws IOException {
  		if (! baseDirectory.isDirectory()) throw new IllegalArgumentException(baseDirectory + " is not a directory.");
  		if (pathElements < 0 || pathElements > 8) throw new IllegalArgumentException();
  
  		long x;
  		synchronized (RND) { x = RND.nextLong(); }
  		final StringBuilder stringBuilder = new StringBuilder();
  		for(int i = 0; i < pathElements; i++) {
  			if (i != 0) stringBuilder.append(File.separatorChar);
  			stringBuilder.append(Long.toHexString(x & 0xF));
  			x >>= 4;
  			stringBuilder.append(Long.toHexString(x & 0xF));
  			x >>= 4;
  		}
  
  		File directory = baseDirectory;
  		if (pathElements > 0) {
  			directory = new File(baseDirectory, stringBuilder.toString());
  			synchronized (CREATION_LOCK) {
  				if ((directory.exists() && ! directory.isDirectory()) || (! directory.exists() && ! directory.mkdirs())) throw new IOException("Cannot create directory " + directory);
  			}
  		}
  
  		return File.createTempFile(prefix, suffix, directory);
  	}
docs: Creates a temporary file with a random hierachical path.
  
  <p> A random hierarchical path of <var>n</var> path elements is a sequence of <var>n</var>
  directories of two hexadecimal digits each, followed by a filename created by {@link File#createTempFile(String, String, File)}.
  
  <p> This method creates an empty file having a random hierarchical path of the specified
  number of path elements under a given base directory, creating all needed directories along
  the hierarchical path (whereas the base directory is expected to already exist).
  
  @param baseDirectory the base directory (it must exist).
  @param pathElements the number of path elements (filename excluded), must be in [0,8]
  @param prefix will be passed to {@link File#createTempFile(String, String, File)}
  @param suffix will be passed to {@link File#createTempFile(String, String, File)}
  @return the temporary file.
  @throws IOException