method2testcases
stringlengths
118
6.63k
### Question: DownloadListenerBunch implements DownloadListener { @Override public void fetchProgress(@NonNull DownloadTask task, int blockIndex, long increaseBytes) { for (DownloadListener listener : listenerList) { listener.fetchProgress(task, blockIndex, increaseBytes); } } DownloadListenerBunch(@NonNull DownloadLis...
### Question: DownloadListenerBunch implements DownloadListener { @Override public void fetchEnd(@NonNull DownloadTask task, int blockIndex, long contentLength) { for (DownloadListener listener : listenerList) { listener.fetchEnd(task, blockIndex, contentLength); } } DownloadListenerBunch(@NonNull DownloadListener[] li...
### Question: DownloadListenerBunch implements DownloadListener { @Override public void taskEnd(@NonNull DownloadTask task, @NonNull EndCause cause, @Nullable Exception realCause) { for (DownloadListener listener : listenerList) { listener.taskEnd(task, cause, realCause); } } DownloadListenerBunch(@NonNull DownloadList...
### Question: DownloadListenerBunch implements DownloadListener { public boolean contain(DownloadListener targetListener) { for (DownloadListener listener : listenerList) { if (listener == targetListener) return true; } return false; } DownloadListenerBunch(@NonNull DownloadListener[] listenerList); @Override void task...
### Question: DownloadListenerBunch implements DownloadListener { public int indexOf(DownloadListener targetListener) { for (int index = 0; index < listenerList.length; index++) { final DownloadListener listener = listenerList[index]; if (listener == targetListener) return index; } return -1; } DownloadListenerBunch(@N...
### Question: DownloadCall extends NamedRunnable implements Comparable<DownloadCall> { @Override protected void finished() { OkDownload.with().downloadDispatcher().finish(this); Util.d(TAG, "call is finished " + task.getId()); } private DownloadCall(DownloadTask task, boolean asyncExecuted, @NonNull DownloadStore stor...
### Question: DownloadCall extends NamedRunnable implements Comparable<DownloadCall> { @SuppressFBWarnings(value = "Eq", justification = "This special case is just for task priority") @Override public int compareTo(@NonNull DownloadCall o) { return o.getPriority() - getPriority(); } private DownloadCall(DownloadTask t...
### Question: DownloadCall extends NamedRunnable implements Comparable<DownloadCall> { void start(final DownloadCache cache, BreakpointInfo info) throws InterruptedException { final int blockCount = info.getBlockCount(); final List<DownloadChain> blockChainList = new ArrayList<>(info.getBlockCount()); final List<Intege...
### Question: DownloadCall extends NamedRunnable implements Comparable<DownloadCall> { void startBlocks(List<DownloadChain> tasks) throws InterruptedException { ArrayList<Future> futures = new ArrayList<>(tasks.size()); try { for (DownloadChain chain : tasks) { futures.add(submitChain(chain)); } blockChainList.addAll(t...
### Question: DownloadCall extends NamedRunnable implements Comparable<DownloadCall> { public boolean cancel() { synchronized (this) { if (canceled) return false; if (finishing) return false; this.canceled = true; } final long startCancelTime = SystemClock.uptimeMillis(); OkDownload.with().downloadDispatcher().flyingCa...
### Question: StatusUtil { @Nullable public static BreakpointInfo getCurrentInfo(@NonNull String url, @NonNull String parentPath, @Nullable String filename) { return getCurrentInfo(createFinder(url, parentPath, filename)); } static boolean isSameTaskPendingOrRunning(@NonNull DownloadTask task); static Status getStatus...
### Question: DownloadCall extends NamedRunnable implements Comparable<DownloadCall> { void assembleBlockAndCallbackFromBeginning(@NonNull BreakpointInfo info, @NonNull BreakpointRemoteCheck remoteCheck, @NonNull ResumeFailedCause failedCause) { Util.assembleBlock(task, info, remoteCheck.getInstanceLength(), remoteChec...
### Question: DownloadChain implements Runnable { @NonNull public synchronized DownloadConnection getConnectionOrCreate() throws IOException { if (cache.isInterrupt()) throw InterruptException.SIGNAL; if (connection == null) { final String url; final String redirectLocation = cache.getRedirectLocation(); if (redirectLo...
### Question: DownloadChain implements Runnable { void start() throws IOException { final CallbackDispatcher dispatcher = OkDownload.with().callbackDispatcher(); final RetryInterceptor retryInterceptor = new RetryInterceptor(); final BreakpointInterceptor breakpointInterceptor = new BreakpointInterceptor(); connectInte...
### Question: DownloadChain implements Runnable { public DownloadConnection.Connected processConnect() throws IOException { if (cache.isInterrupt()) throw InterruptException.SIGNAL; return connectInterceptorList.get(connectIndex++).interceptConnect(this); } private DownloadChain(int blockIndex, @NonNull DownloadTask t...
### Question: DownloadChain implements Runnable { public long processFetch() throws IOException { if (cache.isInterrupt()) throw InterruptException.SIGNAL; return fetchInterceptorList.get(fetchIndex++).interceptFetch(this); } private DownloadChain(int blockIndex, @NonNull DownloadTask task, @NonNull BreakpointInfo inf...
### Question: DownloadChain implements Runnable { public long loopFetch() throws IOException { if (fetchIndex == fetchInterceptorList.size()) { fetchIndex--; } return processFetch(); } private DownloadChain(int blockIndex, @NonNull DownloadTask task, @NonNull BreakpointInfo info, @NonNull Dow...
### Question: DownloadChain implements Runnable { public void flushNoCallbackIncreaseBytes() { if (noCallbackIncreaseBytes == 0) return; callbackDispatcher.dispatch().fetchProgress(task, blockIndex, noCallbackIncreaseBytes); noCallbackIncreaseBytes = 0; } private DownloadChain(int blockIndex, @NonNull DownloadTask tas...
### Question: StatusUtil { @NonNull static DownloadTask createFinder(@NonNull String url, @NonNull String parentPath, @Nullable String filename) { return new DownloadTask.Builder(url, parentPath, filename) .build(); } static boolean isSameTaskPendingOrRunning(@NonNull DownloadTask task); static Status getStatus(@NonNu...
### Question: DownloadChain implements Runnable { public void setResponseContentLength(long responseContentLength) { this.responseContentLength = responseContentLength; } private DownloadChain(int blockIndex, @NonNull DownloadTask task, @NonNull BreakpointInfo info, @NonNull DownloadCache cac...
### Question: DownloadChain implements Runnable { public void cancel() { if (finished.get() || this.currentThread == null) return; currentThread.interrupt(); } private DownloadChain(int blockIndex, @NonNull DownloadTask task, @NonNull BreakpointInfo info, @NonNull DownloadCache cache, @NonNul...
### Question: DownloadChain implements Runnable { @NonNull public BreakpointInfo getInfo() { return this.info; } private DownloadChain(int blockIndex, @NonNull DownloadTask task, @NonNull BreakpointInfo info, @NonNull DownloadCache cache, @NonNull DownloadStore store); long getResponseContent...
### Question: DownloadChain implements Runnable { @NonNull public DownloadCache getCache() { return cache; } private DownloadChain(int blockIndex, @NonNull DownloadTask task, @NonNull BreakpointInfo info, @NonNull DownloadCache cache, @NonNull DownloadStore store); long getResponseContentLeng...
### Question: DownloadChain implements Runnable { public synchronized void releaseConnection() { if (connection != null) { connection.release(); Util.d(TAG, "release connection " + connection + " task[" + task.getId() + "] block[" + blockIndex + "]"); } connection = null; } private DownloadChain(int blockIndex, @NonNu...
### Question: DownloadChain implements Runnable { public void resetConnectForRetry() { connectIndex = 1; releaseConnection(); } private DownloadChain(int blockIndex, @NonNull DownloadTask task, @NonNull BreakpointInfo info, @NonNull DownloadCache cache, @NonNull DownloadStore store); long get...
### Question: DownloadChain implements Runnable { @NonNull public DownloadStore getDownloadStore() { return store; } private DownloadChain(int blockIndex, @NonNull DownloadTask task, @NonNull BreakpointInfo info, @NonNull DownloadCache cache, @NonNull DownloadStore store); long getResponseCon...
### Question: BreakpointLocalCheck { @NonNull public ResumeFailedCause getCauseOrThrow() { if (!infoRight) { return INFO_DIRTY; } else if (!fileExist) { return FILE_NOT_EXIST; } else if (!outputStreamSupport) { return OUTPUT_STREAM_NOT_SUPPORT; } throw new IllegalStateException("No cause find with dirty: " + dirty); } ...
### Question: StatusUtil { public static boolean isSameTaskPendingOrRunning(@NonNull DownloadTask task) { return OkDownload.with().downloadDispatcher().findSameTask(task) != null; } static boolean isSameTaskPendingOrRunning(@NonNull DownloadTask task); static Status getStatus(@NonNull DownloadTask task); static Status...
### Question: BreakpointLocalCheck { public boolean isInfoRightToResume() { final int blockCount = info.getBlockCount(); if (blockCount <= 0) return false; if (info.isChunked()) return false; if (info.getFile() == null) return false; final File fileOnTask = task.getFile(); if (!info.getFile().equals(fileOnTask)) return...
### Question: BreakpointLocalCheck { public boolean isOutputStreamSupportResume() { final boolean supportSeek = OkDownload.with().outputStreamFactory().supportSeek(); if (supportSeek) return true; if (info.getBlockCount() != 1) return false; if (OkDownload.with().processFileStrategy().isPreAllocateLength(task)) return ...
### Question: BreakpointLocalCheck { public boolean isFileExistToResume() { final Uri uri = task.getUri(); if (Util.isUriContentScheme(uri)) { return Util.getSizeFromContentUri(uri) > 0; } else { final File file = task.getFile(); return file != null && file.exists(); } } BreakpointLocalCheck(@NonNull DownloadTask task,...
### Question: DownloadCache { @NonNull MultiPointOutputStream getOutputStream() { if (outputStream == null) throw new IllegalArgumentException(); return outputStream; } DownloadCache(@NonNull MultiPointOutputStream outputStream); private DownloadCache(); boolean isUserCanceled(); boolean isPreAllocateFailed(); boolean...
### Question: DownloadCache { void setRedirectLocation(String redirectLocation) { this.redirectLocation = redirectLocation; } DownloadCache(@NonNull MultiPointOutputStream outputStream); private DownloadCache(); boolean isUserCanceled(); boolean isPreAllocateFailed(); boolean isInterrupt(); void setPreconditionFailed(...
### Question: DownloadCache { public void setPreconditionFailed(IOException realCause) { this.preconditionFailed = true; this.realCause = realCause; } DownloadCache(@NonNull MultiPointOutputStream outputStream); private DownloadCache(); boolean isUserCanceled(); boolean isPreAllocateFailed(); boolean isInterrupt(); vo...
### Question: DownloadCache { void setUserCanceled() { this.userCanceled = true; } DownloadCache(@NonNull MultiPointOutputStream outputStream); private DownloadCache(); boolean isUserCanceled(); boolean isPreAllocateFailed(); boolean isInterrupt(); void setPreconditionFailed(IOException realCause); void setFileBusyAft...
### Question: DownloadCache { public void setFileBusyAfterRun() { this.fileBusyAfterRun = true; } DownloadCache(@NonNull MultiPointOutputStream outputStream); private DownloadCache(); boolean isUserCanceled(); boolean isPreAllocateFailed(); boolean isInterrupt(); void setPreconditionFailed(IOException realCause); void...
### Question: DownloadCache { public void setServerCanceled(IOException realCause) { this.serverCanceled = true; this.realCause = realCause; } DownloadCache(@NonNull MultiPointOutputStream outputStream); private DownloadCache(); boolean isUserCanceled(); boolean isPreAllocateFailed(); boolean isInterrupt(); void setPr...
### Question: DownloadCache { public void setUnknownError(IOException realCause) { this.unknownError = true; this.realCause = realCause; } DownloadCache(@NonNull MultiPointOutputStream outputStream); private DownloadCache(); boolean isUserCanceled(); boolean isPreAllocateFailed(); boolean isInterrupt(); void setPrecon...
### Question: DownloadTask extends IdentifiedTask implements Comparable<DownloadTask> { public static void enqueue(DownloadTask[] tasks, DownloadListener listener) { for (DownloadTask task : tasks) { task.listener = listener; } OkDownload.with().downloadDispatcher().enqueue(tasks); } DownloadTask(String url, Uri uri, i...
### Question: DownloadSerialQueue extends DownloadListener2 implements Runnable { public synchronized void pause() { if (paused) { Util.w(TAG, "require pause this queue(remain " + taskList.size() + "), but" + "it has already been paused"); return; } paused = true; if (runningTask != null) { runningTask.cancel(); taskLi...
### Question: DownloadCache { public void setPreAllocateFailed(IOException realCause) { this.preAllocateFailed = true; this.realCause = realCause; } DownloadCache(@NonNull MultiPointOutputStream outputStream); private DownloadCache(); boolean isUserCanceled(); boolean isPreAllocateFailed(); boolean isInterrupt(); void...
### Question: BreakpointRemoteCheck { public void check() throws IOException { final DownloadStrategy downloadStrategy = OkDownload.with().downloadStrategy(); ConnectTrial connectTrial = createConnectTrial(); connectTrial.executeTrial(); final boolean isAcceptRange = connectTrial.isAcceptRange(); final boolean isChunke...
### Question: BreakpointRemoteCheck { boolean isTrialSpecialPass(int responseCode, long instanceLength, boolean isResumable) { if (responseCode == RANGE_NOT_SATISFIABLE && instanceLength >= 0 && isResumable) { return true; } return false; } BreakpointRemoteCheck(@NonNull DownloadTask task, ...
### Question: BreakpointRemoteCheck { @NonNull public ResumeFailedCause getCauseOrThrow() { if (failedCause == null) { throw new IllegalStateException("No cause find with resumable: " + resumable); } return this.failedCause; } BreakpointRemoteCheck(@NonNull DownloadTask task, @NonNull B...
### Question: DownloadTask extends IdentifiedTask implements Comparable<DownloadTask> { public Builder toBuilder(String anotherUrl, Uri anotherUri) { final Builder builder = new Builder(anotherUrl, anotherUri) .setPriority(priority) .setReadBufferSize(readBufferSize) .setFlushBufferSize(flushBufferSize) .setSyncBufferS...
### Question: DownloadStrategy { public int determineBlockCount(@NonNull DownloadTask task, long totalLength) { if (task.getSetConnectionCount() != null) return task.getSetConnectionCount(); if (totalLength < ONE_CONNECTION_UPPER_LIMIT) { return 1; } if (totalLength < TWO_CONNECTION_UPPER_LIMIT) { return 2; } if (total...
### Question: DownloadStrategy { public boolean isUseMultiBlock(final boolean isAcceptRange) { if (!OkDownload.with().outputStreamFactory().supportSeek()) return false; return isAcceptRange; } ResumeAvailableResponseCheck resumeAvailableResponseCheck( DownloadConnection.Connected connected, int...
### Question: DownloadStrategy { public void inspectFilenameFromResume(@NonNull String filenameOnStore, @NonNull DownloadTask task) { final String filename = task.getFilename(); if (Util.isEmpty(filename)) { task.getFilenameHolder().set(filenameOnStore); } } ResumeAvailableResponseCheck resumeAvailableResponseCheck( ...
### Question: DownloadStrategy { public boolean validFilenameFromStore(@NonNull DownloadTask task) { final String filename = OkDownload.with().breakpointStore() .getResponseFilename(task.getUrl()); if (filename == null) return false; task.getFilenameHolder().set(filename); return true; } ResumeAvailableResponseCheck r...
### Question: DownloadTask extends IdentifiedTask implements Comparable<DownloadTask> { @Nullable public BreakpointInfo getInfo() { if (info == null) info = OkDownload.with().breakpointStore().get(id); return info; } DownloadTask(String url, Uri uri, int priority, int readBufferSize, int flushBufferSize, ...
### Question: DownloadStrategy { public void validFilenameFromResponse(@Nullable String responseFileName, @NonNull DownloadTask task, @NonNull BreakpointInfo info) throws IOException { if (Util.isEmpty(task.getFilename())) { final String filename = determineFilename(responseFileName, task); if (Util.isEmpty(task.getFil...
### Question: 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()) { filen...
### Question: DownloadStrategy { public void inspectNetworkOnWifi(@NonNull DownloadTask task) throws IOException { if (isHasAccessNetworkStatePermission == null) { isHasAccessNetworkStatePermission = Util .checkPermission(Manifest.permission.ACCESS_NETWORK_STATE); } if (!task.isWifiRequired()) return; if (!isHasAccessN...
### Question: DownloadStrategy { public void inspectNetworkAvailable() throws UnknownHostException { if (isHasAccessNetworkStatePermission == null) { isHasAccessNetworkStatePermission = Util .checkPermission(Manifest.permission.ACCESS_NETWORK_STATE); } if (!isHasAccessNetworkStatePermission) return; if (manager == null...
### Question: ConnectTrial { public void executeTrial() throws IOException { OkDownload.with().downloadStrategy().inspectNetworkOnWifi(task); OkDownload.with().downloadStrategy().inspectNetworkAvailable(); DownloadConnection connection = OkDownload.with().connectionFactory().create(task.getUrl()); boolean isNeedTrialHe...
### Question: ConnectTrial { public long getInstanceLength() { return this.instanceLength; } ConnectTrial(@NonNull DownloadTask task, @NonNull BreakpointInfo info); void executeTrial(); long getInstanceLength(); boolean isAcceptRange(); boolean isChunked(); @Nullable String getResponseEtag(); @Nullable String getRespon...
### Question: ConnectTrial { public boolean isAcceptRange() { return this.acceptRange; } ConnectTrial(@NonNull DownloadTask task, @NonNull BreakpointInfo info); void executeTrial(); long getInstanceLength(); boolean isAcceptRange(); boolean isChunked(); @Nullable String getResponseEtag(); @Nullable String getResponseFi...
### Question: ConnectTrial { public boolean isEtagOverdue() { return info.getEtag() != null && !info.getEtag().equals(responseEtag); } ConnectTrial(@NonNull DownloadTask task, @NonNull BreakpointInfo info); void executeTrial(); long getInstanceLength(); boolean isAcceptRange(); boolean isChunked(); @Nullable String get...
### Question: DownloadTask extends IdentifiedTask implements Comparable<DownloadTask> { public static MockTaskForCompare mockTaskForCompare(int id) { return new MockTaskForCompare(id); } DownloadTask(String url, Uri uri, int priority, int readBufferSize, int flushBufferSize, int syncBufferSize, ...
### Question: ConnectTrial { @Nullable public String getResponseFilename() { return responseFilename; } ConnectTrial(@NonNull DownloadTask task, @NonNull BreakpointInfo info); void executeTrial(); long getInstanceLength(); boolean isAcceptRange(); boolean isChunked(); @Nullable String getResponseEtag(); @Nullable Strin...
### Question: ConnectTrial { public int getResponseCode() { return responseCode; } ConnectTrial(@NonNull DownloadTask task, @NonNull BreakpointInfo info); void executeTrial(); long getInstanceLength(); boolean isAcceptRange(); boolean isChunked(); @Nullable String getResponseEtag(); @Nullable String getResponseFilename...
### Question: ConnectTrial { boolean isNeedTrialHeadMethodForInstanceLength( long oldInstanceLength, @NonNull DownloadConnection.Connected connected) { if (oldInstanceLength != CHUNKED_CONTENT_LENGTH) { return false; } final String contentRange = connected.getResponseHeaderField(CONTENT_RANGE); if (contentRange != null...
### Question: ConnectTrial { void trialHeadMethodForInstanceLength() throws IOException { final DownloadConnection connection = OkDownload.with().connectionFactory() .create(task.getUrl()); final DownloadListener listener = OkDownload.with().callbackDispatcher().dispatch(); try { connection.setRequestMethod(METHOD_HEAD...
### Question: UnifiedListenerManager { public synchronized void detachListener(int id) { realListenerMap.remove(id); } UnifiedListenerManager(); synchronized void detachListener(int id); synchronized void addAutoRemoveListenersWhenTaskEnd(int id); synchronized void removeAutoRemoveListenersWhenTaskEnd(int id); synchron...
### Question: DownloadTask extends IdentifiedTask implements Comparable<DownloadTask> { public void replaceListener(@NonNull DownloadListener listener) { this.listener = listener; } DownloadTask(String url, Uri uri, int priority, int readBufferSize, int flushBufferSize, int syncBufferSize, int s...
### Question: UnifiedListenerManager { public synchronized void attachListener(@NonNull DownloadTask task, @NonNull DownloadListener listener) { final int id = task.getId(); ArrayList<DownloadListener> listenerList = realListenerMap.get(id); if (listenerList == null) { listenerList = new ArrayList<>(); realListenerMap....
### Question: UnifiedListenerManager { public synchronized void attachAndEnqueueIfNotRun(@NonNull DownloadTask task, @NonNull DownloadListener listener) { attachListener(task, listener); if (!isTaskPendingOrRunning(task)) { task.enqueue(hostListener); } } UnifiedListenerManager(); synchronized void detachListener(int i...
### Question: UnifiedListenerManager { public synchronized void executeTaskWithUnifiedListener(@NonNull DownloadTask task, @NonNull DownloadListener listener) { attachListener(task, listener); task.execute(hostListener); } UnifiedListenerManager(); synchronized void detachListener(int id); synchronized void addAutoRemo...
### Question: UnifiedListenerManager { public synchronized void addAutoRemoveListenersWhenTaskEnd(int id) { if (autoRemoveListenerIdList.contains(id)) return; autoRemoveListenerIdList.add(id); } UnifiedListenerManager(); synchronized void detachListener(int id); synchronized void addAutoRemoveListenersWhenTaskEnd(int i...
### Question: UnifiedListenerManager { public synchronized void removeAutoRemoveListenersWhenTaskEnd(int id) { autoRemoveListenerIdList.remove((Integer) id); } UnifiedListenerManager(); synchronized void detachListener(int id); synchronized void addAutoRemoveListenersWhenTaskEnd(int id); synchronized void removeAutoRem...
### Question: RedirectUtil { public static boolean isRedirect(int code) { return code == HttpURLConnection.HTTP_MOVED_PERM || code == HttpURLConnection.HTTP_MOVED_TEMP || code == HttpURLConnection.HTTP_SEE_OTHER || code == HttpURLConnection.HTTP_MULT_CHOICE || code == HTTP_TEMPORARY_REDIRECT || code == HTTP_PERMANENT_R...
### Question: RedirectUtil { @NonNull public static String getRedirectedUrl(DownloadConnection.Connected connected, int responseCode) throws IOException { String url = connected.getResponseHeaderField("Location"); if (url == null) { throw new ProtocolException( "Response code is " + responseCode + " but can't find Loca...
### Question: OkDownloadProvider extends ContentProvider { @Override public boolean onCreate() { context = getContext(); return true; } @Override boolean onCreate(); @Nullable @Override Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] ...
### Question: ResumeFailedException extends IOException { public ResumeFailedCause getResumeFailedCause() { return resumeFailedCause; } ResumeFailedException(ResumeFailedCause cause); ResumeFailedCause getResumeFailedCause(); }### Answer: @Test public void construct() { final ResumeFailedCause cause = ResumeFailedCaus...
### Question: OkDownloadProvider extends ContentProvider { @Nullable @Override public Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] selectionArgs, @Nullable String sortOrder) { return null; } @Override boolean onCreate(); @Nullable @Override Cursor query(@...
### Question: OkDownloadProvider extends ContentProvider { @Nullable @Override public String getType(@NonNull Uri uri) { return null; } @Override boolean onCreate(); @Nullable @Override Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String selection, @Nullable String[] ...
### Question: OkDownloadProvider extends ContentProvider { @Nullable @Override public Uri insert(@NonNull Uri uri, @Nullable ContentValues values) { return null; } @Override boolean onCreate(); @Nullable @Override Cursor query(@NonNull Uri uri, @Nullable String[] projection, @Nullable String se...
### Question: OkDownloadProvider extends ContentProvider { @Override public int delete(@NonNull Uri uri, @Nullable String selection, @Nullable String[] selectionArgs) { return 0; } @Override boolean onCreate(); @Nullable @Override Cursor query(@NonNull Uri uri, @Nullable String[] projection, @N...
### Question: OkDownloadProvider extends ContentProvider { @Override public int update(@NonNull Uri uri, @Nullable ContentValues values, @Nullable String selection, @Nullable String[] selectionArgs) { return 0; } @Override boolean onCreate(); @Nullable @Override Cursor query(@NonNull Uri uri, @Nullable String[] projec...
### Question: DownloadContext { public void startOnSerial(DownloadListener listener) { start(listener, true); } DownloadContext(@NonNull DownloadTask[] tasks, @Nullable DownloadContextListener contextListener, @NonNull QueueSet set, @NonNull Handler uiHandler)...
### Question: DownloadContext { public void startOnParallel(DownloadListener listener) { start(listener, false); } DownloadContext(@NonNull DownloadTask[] tasks, @Nullable DownloadContextListener contextListener, @NonNull QueueSet set, @NonNull Handler uiHandl...
### Question: DownloadContext { public void stop() { if (started) OkDownload.with().downloadDispatcher().cancel(tasks); started = false; } DownloadContext(@NonNull DownloadTask[] tasks, @Nullable DownloadContextListener contextListener, @NonNull QueueSet set, ...
### Question: DownloadContext { public AlterContext alter() { return new AlterContext(this); } DownloadContext(@NonNull DownloadTask[] tasks, @Nullable DownloadContextListener contextListener, @NonNull QueueSet set, @NonNull Handler uiHandler); DownloadConte...
### Question: DownloadOkHttp3Connection implements DownloadConnection, DownloadConnection.Connected { @Override public void release() { request = null; if (response != null) response.close(); response = null; } DownloadOkHttp3Connection(@NonNull OkHttpClient client, @NonNull Request.Builde...
### Question: ServerCanceledException extends IOException { public int getResponseCode() { return responseCode; } ServerCanceledException(int responseCode, long currentOffset); int getResponseCode(); }### Answer: @Test public void construct() { int responseCode = 1; long offset = 2; ServerCanceledException exception =...
### Question: DownloadOkHttp3Connection implements DownloadConnection, DownloadConnection.Connected { @Override public InputStream getInputStream() throws IOException { if (response == null) throw new IOException("Please invoke execute first!"); final ResponseBody body = response.body(); if (body == null) throw new IOE...
### Question: DownloadOkHttp3Connection implements DownloadConnection, DownloadConnection.Connected { @Override public Connected execute() throws IOException { request = requestBuilder.build(); response = client.newCall(request).execute(); return this; } DownloadOkHttp3Connection(@NonNull OkHttpClient client, ...
### Question: DownloadOkHttp3Connection implements DownloadConnection, DownloadConnection.Connected { @Override public int getResponseCode() throws IOException { if (response == null) throw new IOException("Please invoke execute first!"); return response.code(); } DownloadOkHttp3Connection(@NonNull OkHttpClient client,...
### Question: DownloadOkHttp3Connection implements DownloadConnection, DownloadConnection.Connected { @Override public boolean setRequestMethod(@NonNull String method) throws ProtocolException { this.requestBuilder.method(method, null); return true; } DownloadOkHttp3Connection(@NonNull OkHttpClient client, ...
### Question: DownloadOkHttp3Connection implements DownloadConnection, DownloadConnection.Connected { @Override public String getRedirectLocation() { final Response priorRes = response.priorResponse(); if (priorRes != null && response.isSuccessful() && RedirectUtil.isRedirect(priorRes.code())) { return response.request...
### Question: BreakpointInfoRow { public BreakpointInfo toInfo() { final BreakpointInfo info = new BreakpointInfo(id, url, new File(parentPath), filename, taskOnlyProvidedParentPath); info.setEtag(etag); info.setChunked(chunked); return info; } BreakpointInfoRow(Cursor cursor); int getId(); String getUrl(); String getE...
### Question: BreakpointStoreOnSQLite implements DownloadStore { @Override public boolean update(@NonNull BreakpointInfo breakpointInfo) throws IOException { final boolean result = onCache.update(breakpointInfo); helper.updateInfo(breakpointInfo); final String filename = breakpointInfo.getFilename(); Util.d(TAG, "updat...
### Question: BreakpointStoreOnSQLite implements DownloadStore { @Nullable @Override public BreakpointInfo getAfterCompleted(int id) { return null; } BreakpointStoreOnSQLite(BreakpointSQLiteHelper helper, BreakpointStoreOnCache onCache); BreakpointStoreOnSQLite(Context context); @Nullable @Override BreakpointInfo get(...
### Question: BreakpointStoreOnSQLite implements DownloadStore { @Override public boolean markFileDirty(int id) { if (onCache.markFileDirty(id)) { helper.markFileDirty(id); return true; } return false; } BreakpointStoreOnSQLite(BreakpointSQLiteHelper helper, BreakpointStoreOnCache onCache); BreakpointStoreOnSQLite(Con...
### Question: BreakpointStoreOnSQLite implements DownloadStore { @Override public boolean markFileClear(int id) { if (onCache.markFileClear(id)) { helper.markFileClear(id); return true; } return false; } BreakpointStoreOnSQLite(BreakpointSQLiteHelper helper, BreakpointStoreOnCache onCache); BreakpointStoreOnSQLite(Con...
### Question: DownloadUrlConnection implements DownloadConnection, DownloadConnection.Connected { @Override public void addHeader(String name, String value) { connection.addRequestProperty(name, value); } DownloadUrlConnection(URLConnection connection); DownloadUrlConnection(URLConnection connection, IRedirectHandler...
### Question: BreakpointStoreOnSQLite implements DownloadStore { @Override public boolean isFileDirty(int id) { return onCache.isFileDirty(id); } BreakpointStoreOnSQLite(BreakpointSQLiteHelper helper, BreakpointStoreOnCache onCache); BreakpointStoreOnSQLite(Context context); @Nullable @Override BreakpointInfo get(int ...
### Question: BlockInfoRow { public BlockInfo toInfo() { return new BlockInfo(startOffset, contentLength, currentOffset); } BlockInfoRow(Cursor cursor); int getBreakpointId(); long getStartOffset(); long getContentLength(); long getCurrentOffset(); BlockInfo toInfo(); }### Answer: @Test public void toInfo() { final Bl...
### Question: BreakpointSQLiteHelper extends SQLiteOpenHelper { @Override public void onCreate(SQLiteDatabase db) { db.execSQL("CREATE TABLE IF NOT EXISTS " + BREAKPOINT_TABLE_NAME + "( " + ID + " INTEGER PRIMARY KEY, " + URL + " VARCHAR NOT NULL, " + ETAG + " VARCHAR, " + PARENT_PATH + " VARCHAR NOT NULL, " + FILENAME...
### Question: BreakpointSQLiteHelper extends SQLiteOpenHelper { @Override public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { if (oldVersion == 1 && newVersion == 2) { db.execSQL("CREATE TABLE IF NOT EXISTS " + RESPONSE_FILENAME_TABLE_NAME + "( " + URL + " VARCHAR NOT NULL PRIMARY KEY, " + FILENA...