private String findTempDirectory (Properties config)
	{
		String defaultTempDir = System.getProperty("java.io.tmpdir");
		String tempDir = config.getProperty(CONFIG_KEYS.TEMP_DIR.toString());
		
		// no custom temp directory specified?
		// then use standard temp directory
		if (StringUtils.isEmpty(tempDir))
			return defaultTempDir;
		
		// make sure directory does not end with slash
		while(tempDir.endsWith("/"))
		{
			tempDir = tempDir.substring(0, tempDir.length()-1);
		}
		
		
		File dir = new File(tempDir);
		
		if (dir.exists() && dir.isFile())
		{
			LOG.error("Unable to use '" + tempDir + "' as temporary directory. Already exists as file. Using standard temp directory.");
			return defaultTempDir;
		}
		
		if (!dir.exists())
		{
			if (!dir.mkdir())
			{
				LOG.error("Unable to create temp directory '" + tempDir + "'. Using standard temp directory.");
				return defaultTempDir;
			}
		}
		
		// check if we can write to temp directory
		File sample = new File(tempDir, "test.txt");
		
		try {
			if (!sample.createNewFile())
			{
				LOG.error("Unable to write to temp directory '" + tempDir + "'. Using standard temp directory.");
				return defaultTempDir;
			}
			
			sample.delete();
		} catch (IOException e) {
			LOG.error("Unable to write to temp directory '" + tempDir + "'. Using standard temp directory.");
			return defaultTempDir;
		}
		
		// all checks ok, so use custom temp directory
		return tempDir;
		
	}