FileDownloadUtils { public static String parseContentDisposition(String contentDisposition) { if (contentDisposition == null) { return null; } try { Matcher m = CONTENT_DISPOSITION_WITH_ASTERISK_PATTERN.matcher(contentDisposition); if (m.find()) { String charset = m.group(1); String encodeFileName = m.group(2); return URLDecoder.decode(encodeFileName, charset); } m = CONTENT_DISPOSITION_WITHOUT_ASTERISK_PATTERN.matcher(contentDisposition); if (m.find()) { return m.group(1); } } catch (IllegalStateException | UnsupportedEncodingException ignore) { } return null; }  static void setMinProgressStep(int minProgressStep); static void setMinProgressTime(long minProgressTime); static int getMinProgressStep(); static long getMinProgressTime(); @SuppressWarnings({"SameReturnValue", "UnusedParameters"}) static boolean isFilenameValid(String filename); static String getDefaultSaveRootPath(); static String getDefaultSaveFilePath(final String url); static String generateFileName(final String url); static String generateFilePath(String directory, String filename); static void setDefaultSaveRootPath(final String path); static String getTempPath(final String targetPath); static int generateId(final String url, final String path); static int generateId(final String url, final String path,
                                 final boolean pathAsDirectory); static String md5(String string); static String getStack(); static String getStack(final boolean printLine); static String getStack(final StackTraceElement[] stackTrace, final boolean printLine); static boolean isDownloaderProcess(final Context context); static String[] convertHeaderString(final String nameAndValuesString); static long getFreeSpaceBytes(final String path); static String formatString(final String msg, Object... args); @SuppressWarnings("ResultOfMethodCallIgnored") static void markConverted(final Context context); static boolean isFilenameConverted(final Context context); static File getConvertedMarkedFile(final Context context); static long parseContentRangeFoInstanceLength(String contentRange); static String parseContentDisposition(String contentDisposition); static String getTargetFilePath(String path, boolean pathAsDirectory, String filename); static String getParent(final String path); static String getThreadPoolName(String name); static boolean isNetworkNotOnWifiType(); static boolean checkPermission(String permission); static long convertContentLengthString(String s); static String findEtag(final int id, FileDownloadConnection connection); static boolean isAcceptRange(int responseCode, FileDownloadConnection connection); static long findInstanceLengthForTrial(FileDownloadConnection connection); static long findInstanceLengthFromContentRange(FileDownloadConnection connection); static long findContentLength(final int id, FileDownloadConnection connection); static long findContentLengthFromContentRange(FileDownloadConnection connection); static long parseContentLengthFromContentRange(String contentRange); static String findFilename(FileDownloadConnection connection, String url); static FileDownloadOutputStream createOutputStream(final String path); static boolean isBreakpointAvailable(final int id, final FileDownloadModel model); static boolean isBreakpointAvailable(final int id, final FileDownloadModel model,
                                                final Boolean outputStreamSupportSeek); static boolean isBreakpointAvailable(final int id, final FileDownloadModel model,
                                                final String path,
                                                final Boolean outputStreamSupportSeek); static void deleteTaskFiles(String targetFilepath, String tempFilePath); static void deleteTempFile(String tempFilePath); static void deleteTargetFile(String targetFilePath); static boolean isNeedSync(long bytesDelta, long timestampDelta); static String defaultUserAgent(); static boolean needMakeServiceForeground(Context context);  }
@Test public void parseContentDisposition() { String filename = FileDownloadUtils .parseContentDisposition("attachment; ...filename ii=\"hello world\""); assertThat(filename).isNull(); filename = FileDownloadUtils .parseContentDisposition("attachment; filename=\"hello world\""); assertThat(filename).isEqualTo("hello world"); filename = FileDownloadUtils .parseContentDisposition("attachment; filename=genome.jpeg\nabc"); assertThat(filename).isEqualTo("genome.jpeg"); filename = FileDownloadUtils .parseContentDisposition( "attachment; filename*=\"gb2312''%d4%b4%ce%c4%bc%fe.mp3\""); assertThat(filename).isEqualTo("源文件.mp3"); filename = FileDownloadUtils .parseContentDisposition("attachment; filename*=gb2312''%d4%b4%ce%c4%bc%fe.mp3"); assertThat(filename).isEqualTo("源文件.mp3"); filename = FileDownloadUtils .parseContentDisposition( "attachment; filename*=\"UTF-8''%e6%ba%90%e6%96%87%e4%bb%b6.mp3\""); assertThat(filename).isEqualTo("源文件.mp3"); filename = FileDownloadUtils .parseContentDisposition("attachment;filename*=\"UTF8''1.mp3\""); assertThat(filename).isEqualTo("1.mp3"); }