本文整理汇总了Java中com.liulishuo.filedownloader.model.ConnectionModel.setId方法的典型用法代码示例。如果您正苦于以下问题:Java ConnectionModel.setId方法的具体用法?Java ConnectionModel.setId怎么用?Java ConnectionModel.setId使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.liulishuo.filedownloader.model.ConnectionModel
的用法示例。
在下文中一共展示了ConnectionModel.setId方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: findConnectionModel
import com.liulishuo.filedownloader.model.ConnectionModel; //导入方法依赖的package包/类
@Override
public List<ConnectionModel> findConnectionModel(int id) {
final List<ConnectionModel> resultList = new ArrayList<>();
Cursor c = null;
try {
c = db.rawQuery(FileDownloadUtils.formatString("SELECT * FROM %s WHERE %s = ?",
CONNECTION_TABLE_NAME, ConnectionModel.ID), new String[]{Integer.toString(id)});
while (c.moveToNext()) {
final ConnectionModel model = new ConnectionModel();
model.setId(id);
model.setIndex(c.getInt(c.getColumnIndex(ConnectionModel.INDEX)));
model.setStartOffset(c.getInt(c.getColumnIndex(ConnectionModel.START_OFFSET)));
model.setCurrentOffset(c.getInt(c.getColumnIndex(ConnectionModel.CURRENT_OFFSET)));
model.setEndOffset(c.getInt(c.getColumnIndex(ConnectionModel.END_OFFSET)));
resultList.add(model);
}
} finally {
if (c != null)
c.close();
}
return resultList;
}
示例2: findConnectionModel
import com.liulishuo.filedownloader.model.ConnectionModel; //导入方法依赖的package包/类
@Override
public List<ConnectionModel> findConnectionModel(int id) {
final List<ConnectionModel> resultList = new ArrayList<>();
Cursor c = null;
try {
c = db.rawQuery(FileDownloadUtils.formatString("SELECT * FROM %s WHERE %s = ?",
CONNECTION_TABLE_NAME, ConnectionModel.ID), new String[]{Integer.toString(id)});
while (c.moveToNext()) {
final ConnectionModel model = new ConnectionModel();
model.setId(id);
model.setIndex(c.getInt(c.getColumnIndex(ConnectionModel.INDEX)));
model.setStartOffset(c.getLong(c.getColumnIndex(ConnectionModel.START_OFFSET)));
model.setCurrentOffset(c.getLong(c.getColumnIndex(ConnectionModel.CURRENT_OFFSET)));
model.setEndOffset(c.getLong(c.getColumnIndex(ConnectionModel.END_OFFSET)));
resultList.add(model);
}
} finally {
if (c != null)
c.close();
}
return resultList;
}
示例3: findConnectionModel
import com.liulishuo.filedownloader.model.ConnectionModel; //导入方法依赖的package包/类
@Override
public List<ConnectionModel> findConnectionModel(int id) {
final List<ConnectionModel> resultList = new ArrayList<>();
Cursor c = null;
try {
c = db.rawQuery(FileDownloadUtils.formatString("SELECT * FROM %s WHERE %s = ?",
CONNECTION_TABLE_NAME, ConnectionModel.ID), new String[]{Integer.toString(id)});
while (c.moveToNext()) {
final ConnectionModel model = new ConnectionModel();
model.setId(id);
model.setIndex(c.getInt(c.getColumnIndex(ConnectionModel.INDEX)));
model.setStartOffset(c.getLong(c.getColumnIndex(ConnectionModel.START_OFFSET)));
model.setCurrentOffset(c.getLong(c.getColumnIndex(ConnectionModel.CURRENT_OFFSET)));
model.setEndOffset(c.getLong(c.getColumnIndex(ConnectionModel.END_OFFSET)));
resultList.add(model);
}
} finally {
if (c != null) c.close();
}
return resultList;
}
示例4: fetchWithMultipleConnectionFromBeginning
import com.liulishuo.filedownloader.model.ConnectionModel; //导入方法依赖的package包/类
private void fetchWithMultipleConnectionFromBeginning(final long totalLength, final int connectionCount) throws InterruptedException {
long startOffset = 0;
final long eachRegion = totalLength / connectionCount;
final int id = model.getId();
final List<ConnectionModel> connectionModelList = new ArrayList<>();
for (int i = 0; i < connectionCount; i++) {
final long endOffset;
if (i == connectionCount - 1) {
// avoid float precision error
endOffset = 0;
} else {
// [startOffset, endOffset)
endOffset = startOffset + eachRegion - 1;
}
final ConnectionModel connectionModel = new ConnectionModel();
connectionModel.setId(id);
connectionModel.setIndex(i);
connectionModel.setStartOffset(startOffset);
connectionModel.setCurrentOffset(startOffset);
connectionModel.setEndOffset(endOffset);
connectionModelList.add(connectionModel);
database.insertConnectionModel(connectionModel);
startOffset += eachRegion;
}
model.setConnectionCount(connectionCount);
database.updateConnectionCount(id, connectionCount);
fetchWithMultipleConnection(connectionModelList, totalLength);
}
示例5: onFinishMaintain
import com.liulishuo.filedownloader.model.ConnectionModel; //导入方法依赖的package包/类
@Override
public void onFinishMaintain() {
if (currentIterator != null) currentIterator.onFinishMaintain();
final int length = needChangeIdList.size();
if (length < 0) return;
db.beginTransaction();
try {
for (int i = 0; i < length; i++) {
final int oldId = needChangeIdList.keyAt(i);
final FileDownloadModel modelWithNewId = needChangeIdList.get(oldId);
db.delete(TABLE_NAME, FileDownloadModel.ID + " = ?", new String[]{String.valueOf(oldId)});
db.insert(TABLE_NAME, null, modelWithNewId.toContentValues());
if (modelWithNewId.getConnectionCount() > 1) {
List<ConnectionModel> connectionModelList = findConnectionModel(oldId);
if (connectionModelList.size() <= 0) continue;
db.delete(CONNECTION_TABLE_NAME, ConnectionModel.ID + " = ?", new String[]{String.valueOf(oldId)});
for (ConnectionModel connectionModel : connectionModelList) {
connectionModel.setId(modelWithNewId.getId());
db.insert(CONNECTION_TABLE_NAME, null, connectionModel.toContentValues());
}
}
}
db.setTransactionSuccessful();
} finally {
db.endTransaction();
}
}
示例6: fetchWithMultiConnectionFromBeginning
import com.liulishuo.filedownloader.model.ConnectionModel; //导入方法依赖的package包/类
private void fetchWithMultiConnectionFromBeginning(final long totalLength,
final int connectionCount)
throws InterruptedException {
long startOffset = 0;
final long eachRegion = totalLength / connectionCount;
final int id = model.getId();
final List<ConnectionModel> connectionModelList = new ArrayList<>();
for (int i = 0; i < connectionCount; i++) {
final long endOffset;
if (i == connectionCount - 1) {
// avoid float precision error
endOffset = 0;
} else {
// [startOffset, endOffset)
endOffset = startOffset + eachRegion - 1;
}
final ConnectionModel connectionModel = new ConnectionModel();
connectionModel.setId(id);
connectionModel.setIndex(i);
connectionModel.setStartOffset(startOffset);
connectionModel.setCurrentOffset(startOffset);
connectionModel.setEndOffset(endOffset);
connectionModelList.add(connectionModel);
database.insertConnectionModel(connectionModel);
startOffset += eachRegion;
}
model.setConnectionCount(connectionCount);
database.updateConnectionCount(id, connectionCount);
fetchWithMultipleConnection(connectionModelList, totalLength);
}
示例7: checkupBeforeFetch
import com.liulishuo.filedownloader.model.ConnectionModel; //导入方法依赖的package包/类
private void checkupBeforeFetch() throws RetryDirectly, DiscardSafely {
final int id = model.getId();
if (model.isPathAsDirectory()) {
// this scope for caring about the case of there is another task is provided
// the same path to store file and the same url.
final String targetFilePath = model.getTargetFilePath();
// get the ID after got the filename.
final int fileCaseId = FileDownloadUtils.generateId(model.getUrl(),
targetFilePath);
// whether the file with the filename has been existed.
if (FileDownloadHelper.inspectAndInflowDownloaded(id,
targetFilePath, isForceReDownload, false)) {
database.remove(id);
database.removeConnections(id);
throw new DiscardSafely();
}
final FileDownloadModel fileCaseModel = database.find(fileCaseId);
if (fileCaseModel != null) {
// the task with the same file name and url has been exist.
// whether the another task with the same file and url is downloading.
if (FileDownloadHelper.inspectAndInflowDownloading(id, fileCaseModel,
threadPoolMonitor, false)) {
//it has been post to upper layer the 'warn' message, so the current
// task no need to continue download.
database.remove(id);
database.removeConnections(id);
throw new DiscardSafely();
}
final List<ConnectionModel> connectionModelList = database.findConnectionModel(fileCaseId);
// the another task with the same file name and url is paused
database.remove(fileCaseId);
database.removeConnections(fileCaseId);
FileDownloadUtils.deleteTargetFile(model.getTargetFilePath());
if (FileDownloadUtils.isBreakpointAvailable(fileCaseId, fileCaseModel)) {
model.setSoFar(fileCaseModel.getSoFar());
model.setTotal(fileCaseModel.getTotal());
model.setETag(fileCaseModel.getETag());
model.setConnectionCount(fileCaseModel.getConnectionCount());
database.update(model);
// re connect to resume from breakpoint.
if (connectionModelList != null) {
for (ConnectionModel connectionModel : connectionModelList) {
connectionModel.setId(id);
database.insertConnectionModel(connectionModel);
}
}
// retry
throw new RetryDirectly();
}
}
// whether there is an another running task with the same target-file-path.
if (FileDownloadHelper.inspectAndInflowConflictPath(id, model.getSoFar(),
model.getTempFilePath(),
targetFilePath,
threadPoolMonitor)) {
database.remove(id);
database.removeConnections(id);
throw new DiscardSafely();
}
}
}
示例8: checkupBeforeFetch
import com.liulishuo.filedownloader.model.ConnectionModel; //导入方法依赖的package包/类
private void checkupBeforeFetch() throws RetryDirectly, DiscardSafely {
final int id = model.getId();
if (model.isPathAsDirectory()) {
// this scope for caring about the case of there is another task is provided
// the same path to store file and the same url.
final String targetFilePath = model.getTargetFilePath();
// get the ID after got the filename.
final int fileCaseId = FileDownloadUtils.generateId(model.getUrl(),
targetFilePath);
// whether the file with the filename has been existed.
if (FileDownloadHelper.inspectAndInflowDownloaded(id,
targetFilePath, isForceReDownload, false)) {
database.remove(id);
database.removeConnections(id);
throw new DiscardSafely();
}
final FileDownloadModel fileCaseModel = database.find(fileCaseId);
if (fileCaseModel != null) {
// the task with the same file name and url has been exist.
// whether the another task with the same file and url is downloading.
if (FileDownloadHelper.inspectAndInflowDownloading(id, fileCaseModel,
threadPoolMonitor, false)) {
//it has been post to upper layer the 'warn' message, so the current
// task no need to continue download.
database.remove(id);
database.removeConnections(id);
throw new DiscardSafely();
}
final List<ConnectionModel> connectionModelList = database
.findConnectionModel(fileCaseId);
// the another task with the same file name and url is paused
database.remove(fileCaseId);
database.removeConnections(fileCaseId);
FileDownloadUtils.deleteTargetFile(model.getTargetFilePath());
if (FileDownloadUtils.isBreakpointAvailable(fileCaseId, fileCaseModel)) {
model.setSoFar(fileCaseModel.getSoFar());
model.setTotal(fileCaseModel.getTotal());
model.setETag(fileCaseModel.getETag());
model.setConnectionCount(fileCaseModel.getConnectionCount());
database.update(model);
// re connect to resume from breakpoint.
if (connectionModelList != null) {
for (ConnectionModel connectionModel : connectionModelList) {
connectionModel.setId(id);
database.insertConnectionModel(connectionModel);
}
}
// retry
throw new RetryDirectly();
}
}
// whether there is an another running task with the same target-file-path.
if (FileDownloadHelper.inspectAndInflowConflictPath(id, model.getSoFar(),
model.getTempFilePath(),
targetFilePath,
threadPoolMonitor)) {
database.remove(id);
database.removeConnections(id);
throw new DiscardSafely();
}
}
}