public static String changeExtension(String fileName, String extension,
			boolean gzipped) {
		extension = (extension.startsWith(".")) ? extension : String.format(
				"%s%s", ".", extension);
		String rgxOne = "^(.+?)(?=((\\.tar)?\\.gz)$)";
		String rgxTwo = "^(.+?)(?=\\.(.*)$)";

		Matcher m = Pattern.compile(rgxOne).matcher(fileName);
		boolean ok = (m.find() && gzipped);

		String name = (ok) ? m.group(1) : fileName;
		String gzip = (ok) ? GZIP_EXT : "";

		m = Pattern.compile(rgxTwo).matcher(name);
		ok = m.find();

		name = (ok) ? m.group(1) : name;

		String finalName = String.format("%s%s%s", name, extension, gzip);
		return finalName;

	}