class BlobUtils {

	static File initStorageDirectory(String storageDirectory) {
		File baseDir;
		if (storageDirectory == null || storageDirectory.trim().isEmpty()) {
			baseDir = new File(System.getProperty("java.io.tmpdir"));
		}
		else {
			baseDir = new File(storageDirectory);
		}

		File storageDir;
		final int MAX_ATTEMPTS = 10;
		int attempt;

		for(attempt = 0; attempt < MAX_ATTEMPTS; attempt++) {
			storageDir = new File(baseDir, String.format(
					"blobStore-%s", UUID.randomUUID().toString()));

			// Create the storage dir if it doesn't exist. Only return it when the operation was
			// successful.
			if (!storageDir.exists() && storageDir.mkdirs()) {
				return storageDir;
			}
		}

		// max attempts exceeded to find a storage directory
		throw new RuntimeException("Could not create storage directory for BLOB store in '" + baseDir + "'.");
	}

	private  BlobUtils();

}