当前位置: 首页>>代码示例>>Java>>正文


Java FileDownloadHelper.inspectAndInflowDownloading方法代码示例

本文整理汇总了Java中com.liulishuo.filedownloader.util.FileDownloadHelper.inspectAndInflowDownloading方法的典型用法代码示例。如果您正苦于以下问题:Java FileDownloadHelper.inspectAndInflowDownloading方法的具体用法?Java FileDownloadHelper.inspectAndInflowDownloading怎么用?Java FileDownloadHelper.inspectAndInflowDownloading使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.liulishuo.filedownloader.util.FileDownloadHelper的用法示例。


在下文中一共展示了FileDownloadHelper.inspectAndInflowDownloading方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: checkupBeforeFetch

import com.liulishuo.filedownloader.util.FileDownloadHelper; //导入方法依赖的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();
        }
    }
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:76,代码来源:DownloadLaunchRunnable.java

示例2: checkupBeforeFetch

import com.liulishuo.filedownloader.util.FileDownloadHelper; //导入方法依赖的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();
        }
    }
}
 
开发者ID:lingochamp,项目名称:FileDownloader,代码行数:77,代码来源:DownloadLaunchRunnable.java


注:本文中的com.liulishuo.filedownloader.util.FileDownloadHelper.inspectAndInflowDownloading方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。