我使用this library,但是当我在我的应用中按“刷新”按钮时,此库会显示错误:
public void refreshList() {
if (isOnline()) {
FileDownloader.getImpl().pauseAll();
final RestServiceApi apiService = ServiceGenerator.createService(RestServiceApi.class, getString(R.string.base_url), remindToken());
getContent(apiService);
} else {
Toast.makeText(MainActivity.this, getString(R.string.no_internet_connection), Toast.LENGTH_SHORT).show();
}
}
onClick按钮“刷新”:
public void saveFilesOnDisk(final List<Folder> folders, final int index) {
final List<File> files = folders.get(index).getFiles();
progressBar.setProgress(0);
progressBar.setMax(files.size());
String downloaderFile = "";
final FileDownloadListener queueTarget = new FileDownloadSampleListener() {
@Override
protected void pending(BaseDownloadTask task, int soFarBytes, int totalBytes) {
Log.i("status: ", "pending");
super.pending(task, soFarBytes, totalBytes);
}
@Override
protected void progress(BaseDownloadTask task, int soFarBytes, int totalBytes) {
Log.i("status: ", "progress");
super.progress(task, soFarBytes, totalBytes);
}
@Override
protected void error(BaseDownloadTask task, Throwable e) {
Log.i("status: ", "error");
super.error(task, e);
//task.reuse();
//saveFilesOnDisk(folders, 0);
}
@Override
protected void connected(BaseDownloadTask task, String etag, boolean isContinue, int soFarBytes, int totalBytes) {
super.connected(task, etag, isContinue, soFarBytes, totalBytes);
Log.i("connected file: ", task.getPath());
}
@Override
protected void paused(BaseDownloadTask task, int soFarBytes, int totalBytes) {
Log.i("status: ", "pause");
super.paused(task, soFarBytes, totalBytes);
}
@Override
protected void completed(BaseDownloadTask task) {
super.completed(task);
Log.i("download: ", "completed; " + homeFolder + java.io.File.separator + task.getPath());
progressBar.setProgress(progressBar.getProgress() + 1);
for (int i = 0; i < files.size(); i++) {
String filePath = homeFolder + java.io.File.separator + files.get(i).getPath().substring(2);
if (filePath.equals(task.getPath())) {
adapter.notifyItemChanged(i);
}
}
if (progressBar.getProgress() == files.size() - 1) {
if (index < folders.size() - 1) {
saveFilesOnDisk(folders, index + 1);
}
}
}
@Override
protected void warn(BaseDownloadTask task) {
Log.i("status: ", "warn");
super.warn(task);
}
};
for (int i = 0; i < files.size(); i++) {
downloaderFile = files.get(i).getPath();
String fullPath = homeFolder + java.io.File.separator + downloaderFile.substring(2);
if (!(new java.io.File(fullPath).exists())) {
final String url;
boolean isDir = false;
url = "http://..." + downloaderFile;
FileDownloader.getImpl().create(url)
.setPath(fullPath, isDir)
.setCallbackProgressTimes(300)
.setMinIntervalUpdateSpeed(400)
.setListener(queueTarget)
.asInQueueTask()
.enqueue();
} else {
progressBar.setProgress(progressBar.getProgress() + 1);
if (index == files.size() - 1) {
saveFilesOnDisk(folders, index + 1);
}
}
}
FileDownloader.getImpl().start(queueTarget, true);
}
getContent(apiService)获取文件列表并调用此方法:
var express = require('express');
var logger = require('morgan');
var bodyParser = require('body-parser');
var api = require('./api/index');
var app = express();
///////////////////////
// Server Middleware
///////////////////////
app.use(logger(app.get("env") === "production" ? "combined" : "dev"));
// parse application/json
app.use(bodyParser.json());
// parse application/x-www-form-urlencoded
app.use(bodyParser.urlencoded({ extended: false }));
// CORS
// This allows client applications from other domains use the API Server
app.use(function(req, res, next) {
res.header("Access-Control-Allow-Origin", "*");
res.header("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept");
next();
});
//////////////////
// API Queries
//////////////////
app.use('/', api);
//////////////////
// Server Setup
//////////////////
app.set("env", process.env.NODE_ENV || "development");
app.set("host", process.env.HOST || "0.0.0.0");
app.set("port", process.env.PORT || 8080);
app.listen(app.get("port"), function () {
console.log('\n' + '**********************************');
console.log('REST API listening on port ' + app.get("port"));
console.log('**********************************' + '\n');
});
////////////////////
// Error Handlers
////////////////////
// catch 404 and forward to error handler
app.use(function(req, res, next) {
var err = new Error('Not Found');
err.status = 404;
next(err);
});
// development error handler
// will print stacktrace
if (app.get('env') === 'development') {
app.use(function(err, req, res, next) {
res.status( err.code || 500 )
.json({
status: 'error',
message: err
});
});
}
// production error handler
// no stacktraces leaked to user
app.use(function(err, req, res, next) {
res.status(err.status || 500)
.json({
status: 'error',
message: err.message
});
});
module.exports = app;
如何处理此错误?我想获取所有文件