public class FileDownloadUtils extends Object
| Constructor and Description |
|---|
FileDownloadUtils() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
checkPermission(String permission) |
static long |
convertContentLengthString(String s) |
static String[] |
convertHeaderString(String nameAndValuesString) |
static FileDownloadOutputStream |
createOutputStream(String path) |
static String |
defaultUserAgent() |
static void |
deleteTargetFile(String targetFilePath) |
static void |
deleteTaskFiles(String targetFilepath,
String tempFilePath) |
static void |
deleteTempFile(String tempFilePath) |
static long |
findContentLength(int id,
FileDownloadConnection connection) |
static long |
findContentLengthFromContentRange(FileDownloadConnection connection) |
static String |
findEtag(int id,
FileDownloadConnection connection) |
static String |
findFilename(FileDownloadConnection connection,
String url) |
static long |
findInstanceLengthForTrial(FileDownloadConnection connection) |
static long |
findInstanceLengthFromContentRange(FileDownloadConnection connection) |
static String |
formatString(String msg,
Object... args) |
static String |
generateFileName(String url) |
static String |
generateFilePath(String directory,
String filename) |
static int |
generateId(String url,
String path) |
static int |
generateId(String url,
String path,
boolean pathAsDirectory) |
static File |
getConvertedMarkedFile(Context context) |
static String |
getDefaultSaveFilePath(String url) |
static String |
getDefaultSaveRootPath() |
static long |
getFreeSpaceBytes(String path) |
static int |
getMinProgressStep() |
static long |
getMinProgressTime() |
static String |
getParent(String path)
The same to
File.getParent(), for non-creating a file object. |
static String |
getStack() |
static String |
getStack(boolean printLine) |
static String |
getStack(StackTraceElement[] stackTrace,
boolean printLine) |
static String |
getTargetFilePath(String path,
boolean pathAsDirectory,
String filename) |
static String |
getTempPath(String targetPath) |
static String |
getThreadPoolName(String name) |
static boolean |
isAcceptRange(int responseCode,
FileDownloadConnection connection) |
static boolean |
isBreakpointAvailable(int id,
FileDownloadModel model) |
static boolean |
isBreakpointAvailable(int id,
FileDownloadModel model,
Boolean outputStreamSupportSeek) |
static boolean |
isBreakpointAvailable(int id,
FileDownloadModel model,
String path,
Boolean outputStreamSupportSeek) |
static boolean |
isDownloaderProcess(Context context) |
static boolean |
isFilenameConverted(Context context) |
static boolean |
isFilenameValid(String filename)
Checks whether the filename looks legitimate.
|
static boolean |
isNeedSync(long bytesDelta,
long timestampDelta) |
static boolean |
isNetworkNotOnWifiType() |
static void |
markConverted(Context context) |
static String |
md5(String string) |
static boolean |
needMakeServiceForeground(Context context) |
static String |
parseContentDisposition(String contentDisposition)
The same to com.android.providers.downloads.Helpers#parseContentDisposition.
|
static long |
parseContentLengthFromContentRange(String contentRange) |
static long |
parseContentRangeFoInstanceLength(String contentRange) |
static void |
setDefaultSaveRootPath(String path)
The path is used as the default directory in the case of the task without set path.
|
static void |
setMinProgressStep(int minProgressStep) |
static void |
setMinProgressTime(long minProgressTime) |
public static void setMinProgressStep(int minProgressStep)
throws IllegalAccessException
minProgressStep - The minimum bytes interval in per step to sync to the file and the
database.
Used for adjudging whether is time to sync the downloaded so far bytes to database and make sure sync the downloaded buffer to local file.
More smaller more frequently, then download more slowly, but will more safer in scene of the process is killed unexpected. Default 65536, which follow the value in com.android.providers.downloads.Constants.IllegalAccessExceptionDownloadStatusCallback.onProgress(long),
setMinProgressTime(long)public static void setMinProgressTime(long minProgressTime)
throws IllegalAccessException
minProgressTime - The minimum millisecond interval in per time to sync to the file and
the database.
Used for adjudging whether is time to sync the downloaded so far bytes to database and make sure sync the downloaded buffer to local file.
More smaller more frequently, then download more slowly, but will more safer in scene of the process is killed unexpected. Default 2000, which follow the value in com.android.providers.downloads.Constants.IllegalAccessExceptionDownloadStatusCallback.onProgress(long),
setMinProgressStep(int)public static int getMinProgressStep()
public static long getMinProgressTime()
public static boolean isFilenameValid(String filename)
public static String getDefaultSaveRootPath()
public static void setDefaultSaveRootPath(String path)
path - default root path for save download file.BaseDownloadTask.setPath(String, boolean)public static String getTempPath(String targetPath)
targetPath - The target path for the download task.targetPath in downloading status; The temp path is used for
storing the file not completed downloaded yet.public static int generateId(String url, String path)
url - The downloading URL.path - The absolute file path.public static int generateId(String url, String path, boolean pathAsDirectory)
url - The downloading URL.path - If pathAsDirectory is true, path would be the absolute
directory to place the file;
If pathAsDirectory is false, path would be the absolute
file path.public static String getStack()
public static String getStack(boolean printLine)
public static String getStack(StackTraceElement[] stackTrace, boolean printLine)
public static boolean isDownloaderProcess(Context context)
context - the contexttrue if the FileDownloadService is allowed to run on the current process,
false otherwise.public static long getFreeSpaceBytes(String path)
public static void markConverted(Context context)
public static boolean isFilenameConverted(Context context)
If true, You can check whether the file has completed downloading with
File.exists() directly.
when FileDownloadService.onCreate() is invoked, This value will be assigned to
true only once since you upgrade the filedownloader version to 0.3.3 or higher.
public static long parseContentRangeFoInstanceLength(String contentRange)
public static String parseContentDisposition(String contentDisposition)
public static String getTargetFilePath(String path, boolean pathAsDirectory, String filename)
path - If pathAsDirectory is true, the path would be the
absolute directory to settle down the file;
If pathAsDirectory is false, the path would be the
absolute file path.pathAsDirectory - whether the path is a directory.filename - the file's name.null.public static String getParent(String path)
File.getParent(), for non-creating a file object.null.public static boolean isNetworkNotOnWifiType()
public static boolean checkPermission(String permission)
public static long convertContentLengthString(String s)
public static String findEtag(int id, FileDownloadConnection connection)
public static boolean isAcceptRange(int responseCode,
FileDownloadConnection connection)
public static long findInstanceLengthForTrial(FileDownloadConnection connection)
public static long findInstanceLengthFromContentRange(FileDownloadConnection connection)
public static long findContentLength(int id,
FileDownloadConnection connection)
public static long findContentLengthFromContentRange(FileDownloadConnection connection)
public static long parseContentLengthFromContentRange(String contentRange)
public static String findFilename(FileDownloadConnection connection, String url) throws FileDownloadSecurityException
FileDownloadSecurityExceptionpublic static FileDownloadOutputStream createOutputStream(String path) throws IOException
IOExceptionpublic static boolean isBreakpointAvailable(int id,
FileDownloadModel model)
public static boolean isBreakpointAvailable(int id,
FileDownloadModel model,
Boolean outputStreamSupportSeek)
public static boolean isBreakpointAvailable(int id,
FileDownloadModel model,
String path,
Boolean outputStreamSupportSeek)
public static void deleteTempFile(String tempFilePath)
public static void deleteTargetFile(String targetFilePath)
public static boolean isNeedSync(long bytesDelta,
long timestampDelta)
public static String defaultUserAgent()
public static boolean needMakeServiceForeground(Context context)