/** {@inheritDoc} */ @Override public boolean download(final String url, final DownloadHandler handler) { boolean result = false; try { handler.handleDownload(new FileInputStream(new File(url))); result = handler.successful(); } catch (final IOException e) { throw new RuntimeException("error testing", e); } return result; }
<T> void executeSelf(final ResponseHandler<T> callback) { HttpLite lite = request.lite; boolean isDownload = callback instanceof DownloadHandler; if (callback instanceof DownloadHandler) ((DownloadHandler) callback).doResumeWork(); final Executor executor = lite.getCustomDownloadExecutor(); if (isDownload && executor != null) { executor.execute( new Runnable() { @Override public void run() { try { callback.onResponse(executeSyncInner(callback)); } catch (Exception e) { callback.onFailed(e); } } }); } else { Executable executable = lite.getClient().executable(request); if (isDownload) { executable = ((DownloadHandler) callback).wrap(executable); } setExecutable(executable); executable().enqueue(callback); } }
private Response executeSyncInner(ResponseHandler callback) throws Exception { HttpLite lite = request.lite; if (callback instanceof DownloadHandler) ((DownloadHandler) callback).doResumeWork(); if (lite.getRequestFilter() != null) lite.getRequestFilter().onRequest(lite, request, callback.resultType()); Executable executable = lite.getClient().executable(request); if (callback instanceof DownloadHandler) executable = ((DownloadHandler) callback).wrap(executable); setExecutable(executable); Response response = executable().execute(); if (lite.getResponseFilter() != null) lite.getResponseFilter().onResponse(lite, request, response); response = request.handleResponse(response); return response; }