public class FileDownloadUtils
extends java.lang.Object
| Constructor and Description |
|---|
FileDownloadUtils() |
| Modifier and Type | Method and Description |
|---|---|
static boolean |
checkPermission(java.lang.String permission) |
static long |
convertContentLengthString(java.lang.String s) |
static java.lang.String[] |
convertHeaderString(java.lang.String nameAndValuesString) |
static FileDownloadOutputStream |
createOutputStream(java.lang.String path) |
static java.lang.String |
defaultUserAgent() |
static void |
deleteTargetFile(java.lang.String targetFilePath) |
static void |
deleteTaskFiles(java.lang.String targetFilepath,
java.lang.String tempFilePath) |
static void |
deleteTempFile(java.lang.String tempFilePath) |
static long |
findContentLength(int id,
FileDownloadConnection connection) |
static long |
findContentLengthFromContentRange(FileDownloadConnection connection) |
static java.lang.String |
findEtag(int id,
FileDownloadConnection connection) |
static java.lang.String |
findFilename(FileDownloadConnection connection,
java.lang.String url) |
static long |
findInstanceLengthForTrial(FileDownloadConnection connection) |
static long |
findInstanceLengthFromContentRange(FileDownloadConnection connection) |
static java.lang.String |
formatString(java.lang.String msg,
java.lang.Object... args) |
static java.lang.String |
generateFileName(java.lang.String url) |
static java.lang.String |
generateFilePath(java.lang.String directory,
java.lang.String filename) |
static int |
generateId(java.lang.String url,
java.lang.String path) |
static int |
generateId(java.lang.String url,
java.lang.String path,
boolean pathAsDirectory) |
static java.io.File |
getConvertedMarkedFile(android.content.Context context) |
static java.lang.String |
getDefaultSaveFilePath(java.lang.String url) |
static java.lang.String |
getDefaultSaveRootPath() |
static long |
getFreeSpaceBytes(java.lang.String path) |
static int |
getMinProgressStep() |
static long |
getMinProgressTime() |
static java.lang.String |
getParent(java.lang.String path)
The same to
File.getParent(), for non-creating a file object. |
static java.lang.String |
getStack() |
static java.lang.String |
getStack(boolean printLine) |
static java.lang.String |
getStack(java.lang.StackTraceElement[] stackTrace,
boolean printLine) |
static java.lang.String |
getTargetFilePath(java.lang.String path,
boolean pathAsDirectory,
java.lang.String filename) |
static java.lang.String |
getTempPath(java.lang.String targetPath) |
static java.lang.String |
getThreadPoolName(java.lang.String name) |
static boolean |
isAcceptRange(int responseCode,
FileDownloadConnection connection) |
static boolean |
isBreakpointAvailable(int id,
FileDownloadModel model) |
static boolean |
isBreakpointAvailable(int id,
FileDownloadModel model,
java.lang.Boolean outputStreamSupportSeek) |
static boolean |
isBreakpointAvailable(int id,
FileDownloadModel model,
java.lang.String path,
java.lang.Boolean outputStreamSupportSeek) |
static boolean |
isDownloaderProcess(android.content.Context context) |
static boolean |
isFilenameConverted(android.content.Context context) |
static boolean |
isFilenameValid(java.lang.String filename)
Checks whether the filename looks legitimate.
|
static boolean |
isNeedSync(long bytesDelta,
long timestampDelta) |
static boolean |
isNetworkNotOnWifiType() |
static void |
markConverted(android.content.Context context) |
static java.lang.String |
md5(java.lang.String string) |
static boolean |
needMakeServiceForeground(android.content.Context context) |
static java.lang.String |
parseContentDisposition(java.lang.String contentDisposition)
The same to com.android.providers.downloads.Helpers#parseContentDisposition.
|
static long |
parseContentLengthFromContentRange(java.lang.String contentRange) |
static long |
parseContentRangeFoInstanceLength(java.lang.String contentRange) |
static void |
setDefaultSaveRootPath(java.lang.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 java.lang.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.java.lang.IllegalAccessExceptionDownloadStatusCallback.onProgress(long),
setMinProgressTime(long)public static void setMinProgressTime(long minProgressTime)
throws java.lang.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.java.lang.IllegalAccessExceptionDownloadStatusCallback.onProgress(long),
setMinProgressStep(int)public static int getMinProgressStep()
public static long getMinProgressTime()
public static boolean isFilenameValid(java.lang.String filename)
public static java.lang.String getDefaultSaveRootPath()
public static java.lang.String getDefaultSaveFilePath(java.lang.String url)
public static java.lang.String generateFileName(java.lang.String url)
public static java.lang.String generateFilePath(java.lang.String directory,
java.lang.String filename)
public static void setDefaultSaveRootPath(java.lang.String path)
path - default root path for save download file.BaseDownloadTask.setPath(String, boolean)public static java.lang.String getTempPath(java.lang.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(java.lang.String url,
java.lang.String path)
url - The downloading URL.path - The absolute file path.public static int generateId(java.lang.String url,
java.lang.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 java.lang.String md5(java.lang.String string)
public static java.lang.String getStack()
public static java.lang.String getStack(boolean printLine)
public static java.lang.String getStack(java.lang.StackTraceElement[] stackTrace,
boolean printLine)
public static boolean isDownloaderProcess(android.content.Context context)
context - the contexttrue if the FileDownloadService is allowed to run on the current process,
false otherwise.public static java.lang.String[] convertHeaderString(java.lang.String nameAndValuesString)
public static long getFreeSpaceBytes(java.lang.String path)
public static java.lang.String formatString(java.lang.String msg,
java.lang.Object... args)
public static void markConverted(android.content.Context context)
public static boolean isFilenameConverted(android.content.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 java.io.File getConvertedMarkedFile(android.content.Context context)
public static long parseContentRangeFoInstanceLength(java.lang.String contentRange)
public static java.lang.String parseContentDisposition(java.lang.String contentDisposition)
public static java.lang.String getTargetFilePath(java.lang.String path,
boolean pathAsDirectory,
java.lang.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 java.lang.String getParent(java.lang.String path)
File.getParent(), for non-creating a file object.null.public static java.lang.String getThreadPoolName(java.lang.String name)
public static boolean isNetworkNotOnWifiType()
public static boolean checkPermission(java.lang.String permission)
public static long convertContentLengthString(java.lang.String s)
public static java.lang.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(java.lang.String contentRange)
public static java.lang.String findFilename(FileDownloadConnection connection, java.lang.String url) throws FileDownloadSecurityException
FileDownloadSecurityExceptionpublic static FileDownloadOutputStream createOutputStream(java.lang.String path) throws java.io.IOException
java.io.IOExceptionpublic static boolean isBreakpointAvailable(int id,
FileDownloadModel model)
public static boolean isBreakpointAvailable(int id,
FileDownloadModel model,
java.lang.Boolean outputStreamSupportSeek)
public static boolean isBreakpointAvailable(int id,
FileDownloadModel model,
java.lang.String path,
java.lang.Boolean outputStreamSupportSeek)
public static void deleteTaskFiles(java.lang.String targetFilepath,
java.lang.String tempFilePath)
public static void deleteTempFile(java.lang.String tempFilePath)
public static void deleteTargetFile(java.lang.String targetFilePath)
public static boolean isNeedSync(long bytesDelta,
long timestampDelta)
public static java.lang.String defaultUserAgent()
public static boolean needMakeServiceForeground(android.content.Context context)