method2testcases
stringlengths
118
6.63k
### Question: BreakpointSQLiteHelper extends SQLiteOpenHelper { public void markFileDirty(int id) { final SQLiteDatabase db = getWritableDatabase(); ContentValues values = new ContentValues(1); values.put(ID, id); db.insert(TASK_FILE_DIRTY_TABLE_NAME, null, values); } BreakpointSQLiteHelper(Context context); @Override ...
### Question: BreakpointSQLiteHelper extends SQLiteOpenHelper { public void markFileClear(int id) { getWritableDatabase().delete(TASK_FILE_DIRTY_TABLE_NAME, ID + " = ?", new String[]{String.valueOf(id)}); } BreakpointSQLiteHelper(Context context); @Override void onOpen(SQLiteDatabase db); @Override void onCreate(SQLite...
### Question: BreakpointSQLiteHelper extends SQLiteOpenHelper { public List<Integer> loadDirtyFileList() { final List<Integer> dirtyFileList = new ArrayList<>(); Cursor cursor = null; try { cursor = getWritableDatabase().rawQuery("SELECT * FROM " + TASK_FILE_DIRTY_TABLE_NAME, null); while (cursor.moveToNext()) { dirtyF...
### Question: BreakpointSQLiteHelper extends SQLiteOpenHelper { public SparseArray<BreakpointInfo> loadToCache() { Cursor breakpointCursor = null; Cursor blockCursor = null; final SQLiteDatabase db = getWritableDatabase(); final List<BreakpointInfoRow> breakpointInfoRows = new ArrayList<>(); final List<BlockInfoRow> bl...
### Question: BreakpointSQLiteHelper extends SQLiteOpenHelper { public void updateBlockIncrease(@NonNull BreakpointInfo info, int blockIndex, long newCurrentOffset) { final ContentValues values = new ContentValues(); values.put(CURRENT_OFFSET, newCurrentOffset); getWritableDatabase().update(BLOCK_TABLE_NAME, values, HO...
### Question: BreakpointSQLiteHelper extends SQLiteOpenHelper { public void updateInfo(@NonNull BreakpointInfo info) throws IOException { final SQLiteDatabase db = getWritableDatabase(); Cursor cursor = null; db.beginTransaction(); try { cursor = getWritableDatabase().rawQuery( "SELECT " + ID + " FROM " + BREAKPOINT_TA...
### Question: DownloadUrlConnection implements DownloadConnection, DownloadConnection.Connected { @Override public Connected execute() throws IOException { final Map<String, List<String>> headerProperties = getRequestProperties(); connection.connect(); redirectHandler.handleRedirect(this, this, headerProperties); retur...
### Question: BreakpointSQLiteHelper extends SQLiteOpenHelper { public void removeInfo(int id) { getWritableDatabase().delete(BREAKPOINT_TABLE_NAME, ID + " = ?", new String[]{String.valueOf(id)}); removeBlock(id); } BreakpointSQLiteHelper(Context context); @Override void onOpen(SQLiteDatabase db); @Override void onCrea...
### Question: BreakpointSQLiteHelper extends SQLiteOpenHelper { public void removeBlock(int breakpointId) { getWritableDatabase().delete(BLOCK_TABLE_NAME, HOST_ID + " = ?", new String[]{String.valueOf(breakpointId)}); } BreakpointSQLiteHelper(Context context); @Override void onOpen(SQLiteDatabase db); @Override void on...
### Question: RemitSyncExecutor implements Handler.Callback { void shutdown() { this.handler.getLooper().quit(); } RemitSyncExecutor(@NonNull RemitAgent agent); RemitSyncExecutor(@NonNull RemitAgent agent, @Nullable Handler handler, @NonNull Set<Integer> freeToDBIdList); void postSyncInfoDelay(i...
### Question: RemitSyncExecutor implements Handler.Callback { boolean isFreeToDatabase(int id) { return freeToDBIdList.contains(id); } RemitSyncExecutor(@NonNull RemitAgent agent); RemitSyncExecutor(@NonNull RemitAgent agent, @Nullable Handler handler, @NonNull Set<Integer> freeToDBIdList); void...
### Question: RemitSyncExecutor implements Handler.Callback { public void postSyncInfoDelay(int id, long delayMillis) { handler.sendEmptyMessageDelayed(id, delayMillis); } RemitSyncExecutor(@NonNull RemitAgent agent); RemitSyncExecutor(@NonNull RemitAgent agent, @Nullable Handler handler, @NonNu...
### Question: RemitSyncExecutor implements Handler.Callback { public void postSync(int id) { handler.sendEmptyMessage(id); } RemitSyncExecutor(@NonNull RemitAgent agent); RemitSyncExecutor(@NonNull RemitAgent agent, @Nullable Handler handler, @NonNull Set<Integer> freeToDBIdList); void postSyncI...
### Question: RemitSyncExecutor implements Handler.Callback { public void postRemoveInfo(int id) { Message message = handler.obtainMessage(WHAT_REMOVE_INFO); message.arg1 = id; handler.sendMessage(message); } RemitSyncExecutor(@NonNull RemitAgent agent); RemitSyncExecutor(@NonNull RemitAgent agent, @Nullable Handler ...
### Question: RemitSyncExecutor implements Handler.Callback { public void postRemoveFreeIds(List<Integer> idList) { final Message message = handler.obtainMessage(WHAT_REMOVE_FREE_BUNCH_ID); message.obj = idList; handler.sendMessage(message); } RemitSyncExecutor(@NonNull RemitAgent agent); RemitSyncExecutor(@NonNull R...
### Question: RemitSyncExecutor implements Handler.Callback { public void postRemoveFreeId(int id) { final Message message = handler.obtainMessage(WHAT_REMOVE_FREE_ID); message.arg1 = id; handler.sendMessage(message); } RemitSyncExecutor(@NonNull RemitAgent agent); RemitSyncExecutor(@NonNull RemitAgent agent, @Nullab...
### Question: RemitSyncExecutor implements Handler.Callback { void removePostWithId(int id) { handler.removeMessages(id); } RemitSyncExecutor(@NonNull RemitAgent agent); RemitSyncExecutor(@NonNull RemitAgent agent, @Nullable Handler handler, @NonNull Set<Integer> freeToDBIdList); void postSyncIn...
### Question: DownloadUrlConnection implements DownloadConnection, DownloadConnection.Connected { @Override public int getResponseCode() throws IOException { if (connection instanceof HttpURLConnection) { return ((HttpURLConnection) connection).getResponseCode(); } return DownloadConnection.NO_RESPONSE_CODE; } Download...
### Question: RemitSyncExecutor implements Handler.Callback { void removePostWithIds(int[] ids) { for (int id : ids) { handler.removeMessages(id); } } RemitSyncExecutor(@NonNull RemitAgent agent); RemitSyncExecutor(@NonNull RemitAgent agent, @Nullable Handler handler, @NonNull Set<Integer> freeT...
### Question: RemitSyncExecutor implements Handler.Callback { public boolean handleMessage(Message msg) { List<Integer> idList; int id; switch (msg.what) { case WHAT_REMOVE_INFO: id = msg.arg1; freeToDBIdList.remove(id); this.agent.removeInfo(id); Util.d(TAG, "remove info " + id); break; case WHAT_REMOVE_FREE_BUNCH_ID:...
### Question: RemitStoreOnSQLite implements RemitSyncExecutor.RemitAgent, DownloadStore { @NonNull @Override public BreakpointInfo createAndInsert(@NonNull DownloadTask task) throws IOException { if (remitHelper.isNotFreeToDatabase(task.getId())) return sqliteCache.createAndInsert(task); return onSQLiteWrapper.createAn...
### Question: RemitStoreOnSQLite implements RemitSyncExecutor.RemitAgent, DownloadStore { @Override public void onTaskStart(int id) { onSQLiteWrapper.onTaskStart(id); remitHelper.onTaskStart(id); } RemitStoreOnSQLite(@NonNull BreakpointStoreOnSQLite sqlite); RemitStoreOnSQLite(@NonNull RemitSyncToDBHelper helper, @No...
### Question: RemitStoreOnSQLite implements RemitSyncExecutor.RemitAgent, DownloadStore { @Override public void onSyncToFilesystemSuccess(@NonNull BreakpointInfo info, int blockIndex, long increaseLength) throws IOException { if (remitHelper.isNotFreeToDatabase(info.getId())) { sqliteCache.onSyncToFilesystemSuccess(inf...
### Question: DownloadUrlConnection implements DownloadConnection, DownloadConnection.Connected { @Override public InputStream getInputStream() throws IOException { return connection.getInputStream(); } DownloadUrlConnection(URLConnection connection); DownloadUrlConnection(URLConnection connection, IRedirectHandler r...
### Question: RemitStoreOnSQLite implements RemitSyncExecutor.RemitAgent, DownloadStore { @Override public boolean update(@NonNull BreakpointInfo info) throws IOException { if (remitHelper.isNotFreeToDatabase(info.getId())) return sqliteCache.update(info); return onSQLiteWrapper.update(info); } RemitStoreOnSQLite(@NonN...
### Question: RemitStoreOnSQLite implements RemitSyncExecutor.RemitAgent, DownloadStore { @Override public void onTaskEnd(int id, @NonNull EndCause cause, @Nullable Exception exception) { sqliteCache.onTaskEnd(id, cause, exception); if (cause == EndCause.COMPLETED) { remitHelper.discard(id); } else { remitHelper.endAnd...
### Question: RemitStoreOnSQLite implements RemitSyncExecutor.RemitAgent, DownloadStore { @Override public void remove(int id) { sqliteCache.remove(id); remitHelper.discard(id); } RemitStoreOnSQLite(@NonNull BreakpointStoreOnSQLite sqlite); RemitStoreOnSQLite(@NonNull RemitSyncToDBHelper helper, @NonNull BreakpointSt...
### Question: RemitStoreOnSQLite implements RemitSyncExecutor.RemitAgent, DownloadStore { @Override public void syncCacheToDB(List<Integer> idList) throws IOException { final SQLiteDatabase database = sqLiteHelper.getWritableDatabase(); database.beginTransaction(); try { for (Integer id : idList) { syncCacheToDB(id); }...
### Question: RemitStoreOnSQLite implements RemitSyncExecutor.RemitAgent, DownloadStore { public static void setRemitToDBDelayMillis(int delayMillis) { final BreakpointStore store = OkDownload.with().breakpointStore(); if (!(store instanceof RemitStoreOnSQLite)) { throw new IllegalStateException( "The current store is ...
### Question: RemitStoreOnSQLite implements RemitSyncExecutor.RemitAgent, DownloadStore { @Override public void removeInfo(int id) { sqLiteHelper.removeInfo(id); } RemitStoreOnSQLite(@NonNull BreakpointStoreOnSQLite sqlite); RemitStoreOnSQLite(@NonNull RemitSyncToDBHelper helper, @NonNull BreakpointStoreOnSQLite sqli...
### Question: DownloadUrlConnection implements DownloadConnection, DownloadConnection.Connected { @Override public Map<String, List<String>> getResponseHeaderFields() { return connection.getHeaderFields(); } DownloadUrlConnection(URLConnection connection); DownloadUrlConnection(URLConnection connection, IRedirectHand...
### Question: RemitStoreOnSQLite implements RemitSyncExecutor.RemitAgent, DownloadStore { @Nullable @Override public BreakpointInfo getAfterCompleted(int id) { return null; } RemitStoreOnSQLite(@NonNull BreakpointStoreOnSQLite sqlite); RemitStoreOnSQLite(@NonNull RemitSyncToDBHelper helper, @NonNull BreakpointStoreOn...
### Question: RemitStoreOnSQLite implements RemitSyncExecutor.RemitAgent, DownloadStore { @Override public boolean markFileDirty(int id) { return onSQLiteWrapper.markFileDirty(id); } RemitStoreOnSQLite(@NonNull BreakpointStoreOnSQLite sqlite); RemitStoreOnSQLite(@NonNull RemitSyncToDBHelper helper, @NonNull Breakpoin...
### Question: RemitStoreOnSQLite implements RemitSyncExecutor.RemitAgent, DownloadStore { @Override public boolean markFileClear(int id) { return onSQLiteWrapper.markFileClear(id); } RemitStoreOnSQLite(@NonNull BreakpointStoreOnSQLite sqlite); RemitStoreOnSQLite(@NonNull RemitSyncToDBHelper helper, @NonNull Breakpoin...
### Question: RemitStoreOnSQLite implements RemitSyncExecutor.RemitAgent, DownloadStore { @Override public boolean isFileDirty(int id) { return onSQLiteWrapper.isFileDirty(id); } RemitStoreOnSQLite(@NonNull BreakpointStoreOnSQLite sqlite); RemitStoreOnSQLite(@NonNull RemitSyncToDBHelper helper, @NonNull BreakpointSto...
### Question: RemitSyncToDBHelper { void shutdown() { this.executor.shutdown(); } RemitSyncToDBHelper(@NonNull final RemitSyncExecutor.RemitAgent agent); RemitSyncToDBHelper(@NonNull final RemitSyncExecutor executor); }### Answer: @Test public void shutdown() { helper.shutdown(); verify(executor).shutdown(); }
### Question: RemitSyncToDBHelper { boolean isNotFreeToDatabase(int id) { return !executor.isFreeToDatabase(id); } RemitSyncToDBHelper(@NonNull final RemitSyncExecutor.RemitAgent agent); RemitSyncToDBHelper(@NonNull final RemitSyncExecutor executor); }### Answer: @Test public void isNotFreeToDatabase() { when(execu...
### Question: RemitSyncToDBHelper { void onTaskStart(int id) { executor.removePostWithId(id); executor.postSyncInfoDelay(id, delayMillis); } RemitSyncToDBHelper(@NonNull final RemitSyncExecutor.RemitAgent agent); RemitSyncToDBHelper(@NonNull final RemitSyncExecutor executor); }### Answer: @Test public void onTaskSt...
### Question: RemitSyncToDBHelper { void endAndEnsureToDB(int id) { executor.removePostWithId(id); try { if (executor.isFreeToDatabase(id)) return; executor.postSync(id); } finally { executor.postRemoveFreeId(id); } } RemitSyncToDBHelper(@NonNull final RemitSyncExecutor.RemitAgent agent); RemitSyncToDBHelper(@NonNull...
### Question: RemitSyncToDBHelper { void discard(int id) { executor.removePostWithId(id); executor.postRemoveInfo(id); } RemitSyncToDBHelper(@NonNull final RemitSyncExecutor.RemitAgent agent); RemitSyncToDBHelper(@NonNull final RemitSyncExecutor executor); }### Answer: @Test public void discard() { helper.discard(1...
### Question: DownloadUrlConnection implements DownloadConnection, DownloadConnection.Connected { @Override public String getResponseHeaderField(String name) { return connection.getHeaderField(name); } DownloadUrlConnection(URLConnection connection); DownloadUrlConnection(URLConnection connection, IRedirectHandler re...
### Question: DownloadUrlConnection implements DownloadConnection, DownloadConnection.Connected { @Override public void release() { try { final InputStream inputStream = connection.getInputStream(); if (inputStream != null) inputStream.close(); } catch (IOException ignored) { } } DownloadUrlConnection(URLConnection con...
### Question: DownloadUrlConnection implements DownloadConnection, DownloadConnection.Connected { @Override public Map<String, List<String>> getRequestProperties() { return connection.getRequestProperties(); } DownloadUrlConnection(URLConnection connection); DownloadUrlConnection(URLConnection connection, IRedirectHa...
### Question: DownloadUrlConnection implements DownloadConnection, DownloadConnection.Connected { @Override public String getRequestProperty(String key) { return connection.getRequestProperty(key); } DownloadUrlConnection(URLConnection connection); DownloadUrlConnection(URLConnection connection, IRedirectHandler redi...
### Question: DownloadUrlConnection implements DownloadConnection, DownloadConnection.Connected { @Override public boolean setRequestMethod(@NonNull String method) throws ProtocolException { if (connection instanceof HttpURLConnection) { ((HttpURLConnection) connection).setRequestMethod(method); return true; } return f...
### Question: DownloadUrlConnection implements DownloadConnection, DownloadConnection.Connected { @Override public String getRedirectLocation() { return redirectHandler.getRedirectLocation(); } DownloadUrlConnection(URLConnection connection); DownloadUrlConnection(URLConnection connection, IRedirectHandler redirectHa...
### Question: Util { public static void setLogger(@Nullable Logger l) { logger = l; } static void enableConsoleLog(); static void setLogger(@Nullable Logger l); static Logger getLogger(); static void e(String tag, String msg, Exception e); static void w(String tag, String msg); static void d(String tag, String msg); s...
### Question: Util { public static void e(String tag, String msg, Exception e) { if (logger != null) { logger.e(tag, msg, e); return; } Log.e(tag, msg, e); } static void enableConsoleLog(); static void setLogger(@Nullable Logger l); static Logger getLogger(); static void e(String tag, String msg, Exception e); static ...
### Question: Util { public static void w(String tag, String msg) { if (logger != null) { logger.w(tag, msg); return; } Log.w(tag, msg); } static void enableConsoleLog(); static void setLogger(@Nullable Logger l); static Logger getLogger(); static void e(String tag, String msg, Exception e); static void w(String tag, ...
### Question: DownloadSerialQueue extends DownloadListener2 implements Runnable { public synchronized void resume() { if (!paused) { Util.w(TAG, "require resume this queue(remain " + taskList.size() + "), but it is" + " still running"); return; } paused = false; if (!taskList.isEmpty() && !looping) { looping = true; st...
### Question: Util { public static void d(String tag, String msg) { if (logger != null) { logger.d(tag, msg); return; } Log.d(tag, msg); } static void enableConsoleLog(); static void setLogger(@Nullable Logger l); static Logger getLogger(); static void e(String tag, String msg, Exception e); static void w(String tag, ...
### Question: Util { public static void i(String tag, String msg) { if (logger != null) { logger.i(tag, msg); return; } Log.i(tag, msg); } static void enableConsoleLog(); static void setLogger(@Nullable Logger l); static Logger getLogger(); static void e(String tag, String msg, Exception e); static void w(String tag, ...
### Question: Util { public static boolean isEmpty(@Nullable CharSequence str) { return str == null || str.length() == 0; } static void enableConsoleLog(); static void setLogger(@Nullable Logger l); static Logger getLogger(); static void e(String tag, String msg, Exception e); static void w(String tag, String msg); st...
### Question: Util { public static ThreadFactory threadFactory(final String name, final boolean daemon) { return new ThreadFactory() { @Override public Thread newThread(@NonNull Runnable runnable) { final Thread result = new Thread(runnable, name); result.setDaemon(daemon); return result; } }; } static void enableCons...
### Question: Util { @Nullable public static String md5(String string) { byte[] hash = null; try { hash = MessageDigest.getInstance("MD5").digest(string.getBytes("UTF-8")); } catch (NoSuchAlgorithmException | UnsupportedEncodingException ignored) { } if (hash != null) { StringBuilder hex = new StringBuilder(hash.length...
### Question: Util { public static boolean isCorrectFull(long fetchedLength, long contentLength) { return fetchedLength == contentLength; } static void enableConsoleLog(); static void setLogger(@Nullable Logger l); static Logger getLogger(); static void e(String tag, String msg, Exception e); static void w(String tag,...
### Question: Util { public static long getFreeSpaceBytes(@NonNull StatFs statFs) { long freeSpaceBytes; if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) { freeSpaceBytes = statFs.getAvailableBytes(); } else { freeSpaceBytes = statFs.getAvailableBlocks() * (long) statFs.getBlockSize(); } return freeSpac...
### Question: Util { public static String humanReadableBytes(long bytes, boolean si) { int unit = si ? 1000 : 1024; if (bytes < unit) return bytes + " B"; int exp = (int) (Math.log(bytes) / Math.log(unit)); String pre = (si ? "kMGTPE" : "KMGTPE").charAt(exp - 1) + (si ? "" : "i"); return String.format(Locale.ENGLISH, "...
### Question: Util { public static @NonNull DownloadStore createDefaultDatabase(Context context) { final String storeOnSqliteClassName = "com.liulishuo.okdownload.core.breakpoint.BreakpointStoreOnSQLite"; try { final Constructor constructor = Class.forName(storeOnSqliteClassName) .getDeclaredConstructor(Context.class);...
### Question: Util { public static @NonNull DownloadConnection.Factory createDefaultConnectionFactory() { final String okhttpConnectionClassName = "com.liulishuo.okdownload.core.connection.DownloadOkHttp3Connection$Factory"; try { final Constructor constructor = Class.forName(okhttpConnectionClassName) .getDeclaredCons...
### Question: DownloadSerialQueue extends DownloadListener2 implements Runnable { public int getWorkingTaskId() { return runningTask != null ? runningTask.getId() : ID_INVALID; } DownloadSerialQueue(); DownloadSerialQueue(DownloadListener listener, ArrayList<DownloadTask> taskList); DownloadSerialQueue(DownloadListe...
### Question: Util { public static long parseContentLength(@Nullable String contentLength) { if (contentLength == null) return CHUNKED_CONTENT_LENGTH; try { return Long.parseLong(contentLength); } catch (NumberFormatException ignored) { Util.d("Util", "parseContentLength failed parse for '" + contentLength + "'"); } re...
### Question: Util { public static long parseContentLengthFromContentRange(@Nullable String contentRange) { if (contentRange == null || contentRange.length() == 0) return CHUNKED_CONTENT_LENGTH; final String pattern = "bytes (\\d+)-(\\d+)/\\d+"; try { final Pattern r = Pattern.compile(pattern); final Matcher m = r.matc...
### Question: Util { public static boolean isNetworkNotOnWifiType(ConnectivityManager manager) { if (manager == null) { Util.w("Util", "failed to get connectivity manager!"); return true; } @SuppressLint("MissingPermission") final NetworkInfo info = manager.getActiveNetworkInfo(); return info == null || info.getType() ...
### Question: Util { public static boolean isNetworkAvailable(ConnectivityManager manager) { if (manager == null) { Util.w("Util", "failed to get connectivity manager!"); return true; } @SuppressLint("MissingPermission") final NetworkInfo info = manager.getActiveNetworkInfo(); return info != null && info.isConnected();...
### Question: Util { @Nullable public static String getFilenameFromContentUri(@NonNull Uri contentUri) { final ContentResolver resolver = OkDownload.with().context().getContentResolver(); final Cursor cursor = resolver.query(contentUri, null, null, null, null); if (cursor != null) { try { cursor.moveToFirst(); return c...
### Question: Util { public static long getSizeFromContentUri(@NonNull Uri contentUri) { final ContentResolver resolver = OkDownload.with().context().getContentResolver(); final Cursor cursor = resolver.query(contentUri, null, null, null, null); if (cursor != null) { try { cursor.moveToFirst(); return cursor .getLong(c...
### Question: Util { public static void addUserRequestHeaderField(@NonNull Map<String, List<String>> userHeaderField, @NonNull DownloadConnection connection) throws IOException { inspectUserHeader(userHeaderField); addRequestHeaderFields(userHeaderField, connection); } static void enableConsoleLog(); static void setLo...
### Question: Util { public static void inspectUserHeader(@NonNull Map<String, List<String>> headerField) throws IOException { if (headerField.containsKey(IF_MATCH) || headerField.containsKey(RANGE)) { throw new IOException(IF_MATCH + " and " + RANGE + " only can be handle by internal!"); } } static void enableConsole...
### Question: DownloadSerialQueue extends DownloadListener2 implements Runnable { public int getWaitingTaskCount() { return taskList.size(); } DownloadSerialQueue(); DownloadSerialQueue(DownloadListener listener, ArrayList<DownloadTask> taskList); DownloadSerialQueue(DownloadListener listener); void setListener(Down...
### Question: Util { public static void addDefaultUserAgent(@NonNull final DownloadConnection connection) { final String userAgent = "OkDownload/" + BuildConfig.VERSION_NAME; connection.addHeader(USER_AGENT, userAgent); } static void enableConsoleLog(); static void setLogger(@Nullable Logger l); static Logger getLogge...
### Question: BreakpointInterceptor implements Interceptor.Connect, Interceptor.Fetch { @NonNull @Override public DownloadConnection.Connected interceptConnect(DownloadChain chain) throws IOException { final DownloadConnection.Connected connected = chain.processConnect(); final BreakpointInfo info = chain.getInfo(); if...
### Question: BreakpointInterceptor implements Interceptor.Connect, Interceptor.Fetch { @Override public long interceptFetch(DownloadChain chain) throws IOException { final long contentLength = chain.getResponseContentLength(); final int blockIndex = chain.getBlockIndex(); final boolean isNotChunked = contentLength != ...
### Question: BreakpointInterceptor implements Interceptor.Connect, Interceptor.Fetch { @IntRange(from = -1) static long getRangeRightFromContentRange(@NonNull String contentRange) { Matcher m = CONTENT_RANGE_RIGHT_VALUE.matcher(contentRange); if (m.find()) { return Long.parseLong(m.group(1)); } return -1; } @NonNull ...
### Question: BreakpointInterceptor implements Interceptor.Connect, Interceptor.Fetch { @IntRange(from = -1) long getExactContentLengthRangeFrom0(@NonNull DownloadConnection.Connected connected) { final String contentRangeField = connected.getResponseHeaderField(CONTENT_RANGE); long contentLength = -1; if (!Util.isEmpt...
### Question: FetchDataInterceptor implements Interceptor.Fetch { @Override public long interceptFetch(DownloadChain chain) throws IOException { if (chain.getCache().isInterrupt()) { throw InterruptException.SIGNAL; } OkDownload.with().downloadStrategy().inspectNetworkOnWifi(chain.getTask()); int fetchLength = inputStr...
### Question: CallServerInterceptor implements Interceptor.Connect { @NonNull @Override public DownloadConnection.Connected interceptConnect(DownloadChain chain) throws IOException { OkDownload.with().downloadStrategy().inspectNetworkOnWifi(chain.getTask()); OkDownload.with().downloadStrategy().inspectNetworkAvailable(...
### Question: DownloadSerialQueue extends DownloadListener2 implements Runnable { public synchronized DownloadTask[] shutdown() { shutedDown = true; if (runningTask != null) runningTask.cancel(); final DownloadTask[] tasks = new DownloadTask[taskList.size()]; taskList.toArray(tasks); taskList.clear(); return tasks; } D...
### Question: RetryInterceptor implements Interceptor.Connect, Interceptor.Fetch { @NonNull @Override public DownloadConnection.Connected interceptConnect(DownloadChain chain) throws IOException { final DownloadCache cache = chain.getCache(); while (true) { try { if (cache.isInterrupt()) { throw InterruptException.SIGN...
### Question: RetryInterceptor implements Interceptor.Connect, Interceptor.Fetch { @Override public long interceptFetch(DownloadChain chain) throws IOException { try { return chain.processFetch(); } catch (IOException e) { chain.getCache().catchException(e); throw e; } } @NonNull @Override DownloadConnection.Connected...
### Question: BreakpointStoreOnCache implements DownloadStore { @NonNull @Override public BreakpointInfo createAndInsert(@NonNull DownloadTask task) { final int id = task.getId(); BreakpointInfo newInfo = new BreakpointInfo(id, task.getUrl(), task.getParentFile(), task.getFilename()); synchronized (this) { storedInfos....
### Question: BreakpointStoreOnCache implements DownloadStore { @Override public void onSyncToFilesystemSuccess(@NonNull BreakpointInfo info, int blockIndex, long increaseLength) throws IOException { final BreakpointInfo onCacheOne = this.storedInfos.get(info.id); if (info != onCacheOne) throw new IOException("Info not...
### Question: DownloadSerialQueue extends DownloadListener2 implements Runnable { @Override public void run() { while (!shutedDown) { final DownloadTask nextTask; synchronized (this) { if (taskList.isEmpty() || paused) { runningTask = null; looping = false; break; } nextTask = taskList.remove(0); } nextTask.execute(lis...
### Question: BreakpointStoreOnCache implements DownloadStore { @Override public boolean update(@NonNull BreakpointInfo breakpointInfo) { final String filename = breakpointInfo.getFilename(); if (breakpointInfo.isTaskOnlyProvidedParentPath() && filename != null) { this.responseFilenameMap.put(breakpointInfo.getUrl(), f...
### Question: BreakpointStoreOnCache implements DownloadStore { @Override public BreakpointInfo findAnotherInfoFromCompare(@NonNull DownloadTask task, @NonNull BreakpointInfo ignored) { final SparseArray<BreakpointInfo> clonedMap; synchronized (this) { clonedMap = storedInfos.clone(); } final int size = clonedMap.size(...
### Question: BreakpointStoreOnCache implements DownloadStore { @Override public synchronized void remove(int id) { storedInfos.remove(id); if (unStoredTasks.get(id) == null) sortedOccupiedIds.remove(Integer.valueOf(id)); keyToIdMap.remove(id); } BreakpointStoreOnCache(); BreakpointStoreOnCache(SparseArray<Breakpoint...
### Question: BreakpointStoreOnCache implements DownloadStore { @Override public synchronized int findOrCreateId(@NonNull DownloadTask task) { final Integer candidate = keyToIdMap.get(task); if (candidate != null) return candidate; final int size = storedInfos.size(); for (int i = 0; i < size; i++) { final BreakpointIn...
### Question: BreakpointStoreOnCache implements DownloadStore { @Nullable @Override public BreakpointInfo getAfterCompleted(int id) { return null; } BreakpointStoreOnCache(); BreakpointStoreOnCache(SparseArray<BreakpointInfo> storedInfos, List<Integer> fileDirtyList, ...
### Question: BreakpointStoreOnCache implements DownloadStore { @Override public boolean markFileDirty(int id) { if (!fileDirtyList.contains(id)) { synchronized (fileDirtyList) { if (!fileDirtyList.contains(id)) { fileDirtyList.add(id); return true; } } } return false; } BreakpointStoreOnCache(); BreakpointStoreOnCac...
### Question: BreakpointStoreOnCache implements DownloadStore { @Override public boolean markFileClear(int id) { synchronized (fileDirtyList) { return fileDirtyList.remove(Integer.valueOf(id)); } } BreakpointStoreOnCache(); BreakpointStoreOnCache(SparseArray<BreakpointInfo> storedInfos, Lis...
### Question: BreakpointStoreOnCache implements DownloadStore { @Override public boolean isFileDirty(int id) { return fileDirtyList.contains(id); } BreakpointStoreOnCache(); BreakpointStoreOnCache(SparseArray<BreakpointInfo> storedInfos, List<Integer> fileDirtyList, ...
### Question: KeyToIdMap { @Nullable public Integer get(@NonNull DownloadTask task) { final Integer candidate = keyToIdMap.get(generateKey(task)); if (candidate != null) return candidate; return null; } KeyToIdMap(); KeyToIdMap(@NonNull HashMap<String, Integer> keyToIdMap, @NonNull SparseArray<String> ...
### Question: DownloadSerialQueue extends DownloadListener2 implements Runnable { @Override public void taskStart(@NonNull DownloadTask task) { this.runningTask = task; } DownloadSerialQueue(); DownloadSerialQueue(DownloadListener listener, ArrayList<DownloadTask> taskList); DownloadSerialQueue(DownloadListener list...
### Question: GsonProvider implements MessageBodyReader<T>, MessageBodyWriter<T> { @Override public long getSize( T t, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType ) { return -1; } GsonProvider(); @Override long getSize( T t, Class<?> type, Type genericType, Annotation[] annotations, M...
### Question: DimlevelService { @PUT @Path("/{id}") public Response setDimlevel(@PathParam("id") String id, DimlevelBean bean) { Response response = null; UUID uuid = null; ElisDataObject data = null; PlatformUser user = null; logRequest("", id); response = ElisResponseBuilder.buildBadRequestResponse(); try { uuid = UU...
### Question: DimlevelService { @GET @Path("/{id}") public Response getDimlevel(@PathParam("id") String id) { Response response = null; UUID uuid = null; Dimmer dimmer = null; logRequest("", id); response = ElisResponseBuilder.buildBadRequestResponse(); try { uuid = UUID.fromString(id); } catch (Exception e) { log(LogS...
### Question: PowerstateService { @GET @Path("/{id}") @Produces(MediaType.APPLICATION_JSON) public Response getPowerstate(@PathParam("id") String id) { Response response = null; UUID uuid = null; PowerSwitch ps = null; logRequest("", id); response = ElisResponseBuilder.buildBadRequestResponse(); try { uuid = UUID.fromS...
### Question: GsonProvider implements MessageBodyReader<T>, MessageBodyWriter<T> { @Override public boolean isWriteable( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType ) { return true; } GsonProvider(); @Override long getSize( T t, Class<?> type, Type genericType, Annotation[] annotation...
### Question: GsonProvider implements MessageBodyReader<T>, MessageBodyWriter<T> { @Override public boolean isReadable( Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType ) { return true; } GsonProvider(); @Override long getSize( T t, Class<?> type, Type genericType, Annotation[] annotations...
### Question: GsonProvider implements MessageBodyReader<T>, MessageBodyWriter<T> { @Override public void writeTo( T object, Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream ) throws IOException, WebApplicationException ...