Java Code Examples for com.liulishuo.filedownloader.util.FileDownloadUtils#formatString()
The following examples show how to use
com.liulishuo.filedownloader.util.FileDownloadUtils#formatString() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DownloadLaunchRunnable.java From FileDownloader with Apache License 2.0 | 6 votes |
private void checkupBeforeConnect() throws FileDownloadGiveUpRetryException { // 1. check whether need access-network-state permission? if (isWifiRequired && !FileDownloadUtils.checkPermission(Manifest.permission.ACCESS_NETWORK_STATE)) { throw new FileDownloadGiveUpRetryException( FileDownloadUtils.formatString("Task[%d] can't start the download runnable," + " because this task require wifi, but user application " + "nor current process has %s, so we can't check whether " + "the network type connection.", model.getId(), Manifest.permission.ACCESS_NETWORK_STATE)); } // 2. check whether need wifi to download? if (isWifiRequired && FileDownloadUtils.isNetworkNotOnWifiType()) { throw new FileDownloadNetworkPolicyException(); } }
Example 2
Source File: DownloadTask.java From FileDownloader with Apache License 2.0 | 6 votes |
private int startTaskUnchecked() { if (isUsing()) { if (isRunning()) { throw new IllegalStateException( FileDownloadUtils.formatString("This task is running %d, if you" + " want to start the same task, please create a new one by" + " FileDownloader.create", getId())); } else { throw new IllegalStateException("This task is dirty to restart, If you want to " + "reuse this task, please invoke #reuse method manually and retry to " + "restart again." + mHunter.toString()); } } if (!isAttached()) { setAttachKeyDefault(); } mHunter.intoLaunchPool(); return getId(); }
Example 3
Source File: DownloadStatusCallback.java From FileDownloader with Apache License 2.0 | 6 votes |
void onConnected(boolean isResume, long totalLength, String etag, String fileName) throws IllegalArgumentException { final String oldEtag = model.getETag(); if (oldEtag != null && !oldEtag.equals(etag)) throw new IllegalArgumentException(FileDownloadUtils.formatString("callback " + "onConnected must with precondition succeed, but the etag is " + "changes(%s != %s)", etag, oldEtag)); // direct processParams.setResuming(isResume); model.setStatus(FileDownloadStatus.connected); model.setTotal(totalLength); model.setETag(etag); model.setFilename(fileName); database.updateConnected(model.getId(), totalLength, etag, fileName); onStatusChanged(FileDownloadStatus.connected); callbackMinIntervalBytes = calculateCallbackMinIntervalBytes(totalLength, callbackProgressMaxCount); needSetProcess.compareAndSet(false, true); }
Example 4
Source File: ConnectionProfile.java From FileDownloader with Apache License 2.0 | 6 votes |
public void processProfile(FileDownloadConnection connection) throws ProtocolException { if (isForceNoRange) return; if (isTrialConnect && FileDownloadProperties.getImpl().trialConnectionHeadMethod) { connection.setRequestMethod("HEAD"); } final String range; if (endOffset == RANGE_INFINITE) { range = FileDownloadUtils.formatString("bytes=%d-", currentOffset); } else { range = FileDownloadUtils .formatString("bytes=%d-%d", currentOffset, endOffset); } connection.addHeader("Range", range); }
Example 5
Source File: FileDownloadBroadcastHandler.java From FileDownloader with Apache License 2.0 | 5 votes |
/** * Parse the {@code intent} from the filedownloader broadcast. * * @param intent the intent from the broadcast. * @return the file download model. */ public static FileDownloadModel parseIntent(Intent intent) { if (!ACTION_COMPLETED.equals(intent.getAction())) { throw new IllegalArgumentException(FileDownloadUtils. formatString("can't recognize the intent with action %s, on the current" + " version we only support action [%s]", intent.getAction(), ACTION_COMPLETED)); } return intent.getParcelableExtra(KEY_MODEL); }
Example 6
Source File: FileDownloadHttpException.java From FileDownloader with Apache License 2.0 | 5 votes |
public FileDownloadHttpException(final int code, final Map<String, List<String>> requestHeaderMap, final Map<String, List<String>> responseHeaderMap) { super(FileDownloadUtils.formatString("response code error: %d, \n request headers: %s \n " + "response headers: %s", code, requestHeaderMap, responseHeaderMap)); this.mCode = code; this.mRequestHeaderMap = cloneSerializableMap(requestHeaderMap); this.mResponseHeaderMap = cloneSerializableMap(requestHeaderMap); }
Example 7
Source File: PathConflictException.java From FileDownloader with Apache License 2.0 | 5 votes |
public PathConflictException(final int anotherSamePathTaskId, final String conflictPath, final String targetFilePath) { super(FileDownloadUtils.formatString("There is an another running task(%d) with the" + " same downloading path(%s), because of they are with the same " + "target-file-path(%s), so if the current task is started, the path of the" + " file is sure to be written by multiple tasks, it is wrong, then you " + "receive this exception to avoid such conflict.", anotherSamePathTaskId, conflictPath, targetFilePath)); mAnotherSamePathTaskId = anotherSamePathTaskId; mDownloadingConflictPath = conflictPath; mTargetFilePath = targetFilePath; }
Example 8
Source File: FileDownloadOutOfSpaceException.java From FileDownloader with Apache License 2.0 | 5 votes |
public FileDownloadOutOfSpaceException(long freeSpaceBytes, long requiredSpaceBytes, long breakpointBytes) { super(FileDownloadUtils.formatString("The file is too large to store, breakpoint in bytes: " + " %d, required space in bytes: %d, but free space in bytes: " + "%d", breakpointBytes, requiredSpaceBytes, freeSpaceBytes)); init(freeSpaceBytes, requiredSpaceBytes, breakpointBytes); }
Example 9
Source File: FileDownloadOutOfSpaceException.java From FileDownloader with Apache License 2.0 | 5 votes |
@TargetApi(Build.VERSION_CODES.GINGERBREAD) public FileDownloadOutOfSpaceException(long freeSpaceBytes, long requiredSpaceBytes, long breakpointBytes, Throwable cause) { super(FileDownloadUtils.formatString("The file is too large to store, breakpoint in bytes: " + " %d, required space in bytes: %d, but free space in bytes: " + "%d", breakpointBytes, requiredSpaceBytes, freeSpaceBytes), cause); init(freeSpaceBytes, requiredSpaceBytes, breakpointBytes); }
Example 10
Source File: FileDownloadMessenger.java From FileDownloader with Apache License 2.0 | 5 votes |
@Override public void reAppointment(BaseDownloadTask.IRunningTask task, BaseDownloadTask.LifeCycleCallback callback) { if (this.mTask != null) { throw new IllegalStateException( FileDownloadUtils.formatString("the messenger is working, can't " + "re-appointment for %s", task)); } init(task, callback); }
Example 11
Source File: FileDownloadModel.java From FileDownloader with Apache License 2.0 | 5 votes |
@Override public String toString() { return FileDownloadUtils.formatString("id[%d], url[%s], path[%s], status[%d], sofar[%s]," + " total[%d], etag[%s], %s", id, url, path, status.get(), soFar, total, eTag, super.toString()); }
Example 12
Source File: QueuesHandler.java From FileDownloader with Apache License 2.0 | 5 votes |
@Override public boolean startQueueSerial(FileDownloadListener listener) { final SerialHandlerCallback callback = new SerialHandlerCallback(); final int attachKey = callback.hashCode(); final List<BaseDownloadTask.IRunningTask> list = FileDownloadList.getImpl(). assembleTasksToStart(attachKey, listener); if (onAssembledTasksToStart(attachKey, list, listener, true)) { return false; } final HandlerThread serialThread = new HandlerThread( FileDownloadUtils.formatString("filedownloader serial thread %s-%d", listener, attachKey)); serialThread.start(); final Handler serialHandler = new Handler(serialThread.getLooper(), callback); callback.setHandler(serialHandler); callback.setList(list); callback.goNext(0); synchronized (mRunningSerialMap) { mRunningSerialMap.put(attachKey, serialHandler); } return true; }
Example 13
Source File: DownloadRunnable.java From FileDownloader with Apache License 2.0 | 5 votes |
public DownloadRunnable build() { if (callback == null || path == null || isWifiRequired == null || connectionIndex == null) { throw new IllegalArgumentException(FileDownloadUtils.formatString("%s %s %B", callback, path, isWifiRequired)); } final ConnectTask connectTask = connectTaskBuilder.build(); return new DownloadRunnable(connectTask.downloadId, connectionIndex, connectTask, callback, isWifiRequired, path); }
Example 14
Source File: BlockCompleteMessage.java From FileDownloader with Apache License 2.0 | 5 votes |
public BlockCompleteMessageImpl(MessageSnapshot snapshot) { super(snapshot.getId()); if (snapshot.getStatus() != FileDownloadStatus.completed) { throw new IllegalArgumentException(FileDownloadUtils.formatString( "can't create the block complete message for id[%d], status[%d]", snapshot.getId(), snapshot.getStatus())); } this.mCompletedSnapshot = snapshot; }
Example 15
Source File: DownloadMgrInitialParams.java From FileDownloader with Apache License 2.0 | 5 votes |
@Override public String toString() { return FileDownloadUtils.formatString("component: database[%s], maxNetworkCount[%s]," + " outputStream[%s], connection[%s], connectionCountAdapter[%s]", mDatabaseCustomMaker, mMaxNetworkThreadCount, mOutputStreamCreator, mConnectionCreator, mConnectionCountAdapter); }
Example 16
Source File: ConnectionProfile.java From FileDownloader with Apache License 2.0 | 4 votes |
@Override public String toString() { return FileDownloadUtils.formatString("range[%d, %d) current offset[%d]", startOffset, endOffset, currentOffset); }
Example 17
Source File: RedirectHandler.java From FileDownloader with Apache License 2.0 | 4 votes |
public static FileDownloadConnection process( final Map<String, List<String>> requestHeaderFields, final FileDownloadConnection connection, List<String> redirectedUrlList) throws IOException, IllegalAccessException { int code = connection.getResponseCode(); String location = connection.getResponseHeaderField("Location"); List<String> redirectLocationList = new ArrayList<>(); int redirectTimes = 0; FileDownloadConnection redirectConnection = connection; while (isRedirect(code)) { if (location == null) { throw new IllegalAccessException(FileDownloadUtils. formatString( "receive %d (redirect) but the location is null with response [%s]", code, redirectConnection.getResponseHeaderFields())); } if (FileDownloadLog.NEED_LOG) { FileDownloadLog.d(RedirectHandler.class, "redirect to %s with %d, %s", location, code, redirectLocationList); } redirectConnection.ending(); redirectConnection = buildRedirectConnection(requestHeaderFields, location); redirectLocationList.add(location); redirectConnection.execute(); code = redirectConnection.getResponseCode(); location = redirectConnection.getResponseHeaderField("Location"); if (++redirectTimes >= MAX_REDIRECT_TIMES) { throw new IllegalAccessException( FileDownloadUtils .formatString("redirect too many times! %s", redirectLocationList)); } } if (redirectedUrlList != null) { redirectedUrlList.addAll(redirectLocationList); } return redirectConnection; }
Example 18
Source File: DownloadTask.java From FileDownloader with Apache License 2.0 | 4 votes |
@Override public String toString() { return FileDownloadUtils.formatString("%d@%s", getId(), super.toString()); }
Example 19
Source File: FileDownloadMessenger.java From FileDownloader with Apache License 2.0 | 4 votes |
@Override public String toString() { return FileDownloadUtils.formatString("%d:%s", mTask == null ? -1 : mTask.getOrigin().getId(), super.toString()); }
Example 20
Source File: MessageSnapshot.java From FileDownloader with Apache License 2.0 | 4 votes |
NoFieldException(String methodName, MessageSnapshot snapshot) { super(FileDownloadUtils.formatString("There isn't a field for '%s' in this message" + " %d %d %s", methodName, snapshot.getId(), snapshot.getStatus(), snapshot.getClass().getName())); }