class DownloadStrategy {

    protected String determineFilename(@Nullable String responseFileName,
                                       @NonNull DownloadTask task) throws IOException {

        if (Util.isEmpty(responseFileName)) {

            final String url = task.getUrl();
            Matcher m = TMP_FILE_NAME_PATTERN.matcher(url);
            String filename = null;
            while (m.find()) {
                filename = m.group(1);
            }

            if (Util.isEmpty(filename)) {
                filename = Util.md5(url);
            }

            if (filename == null) {
                throw new IOException("Can't find valid filename.");
            }

            return filename;
        }

        return responseFileName;
    }

}