/** Abort an ongoing upload or download. */ private void abort(String objectId) { final RequestContext context; synchronized (activeRequests) { context = activeRequests.remove(objectId); } if (context != null) { File file = context.targetFile; if (file != null) { file.delete(); } // Trigger the abort callback immediately to minimize latency between it and abort() being // called. JSONObject error = createFileTransferError(ABORTED_ERR, context.source, context.target, null, -1); synchronized (context) { context.sendPluginResult(new PluginResult(PluginResult.Status.ERROR, error)); context.aborted = true; } // Closing the streams can block, so execute on a background thread. cordova .getThreadPool() .execute( new Runnable() { public void run() { synchronized (context) { safeClose(context.currentInputStream); safeClose(context.currentOutputStream); } } }); } }