(String action)
| 50 | } |
| 51 | |
| 52 | @Override |
| 53 | public String action(String action) { |
| 54 | try { |
| 55 | OkHttp.cancel(TAG); |
| 56 | String name = Uri.parse(action).getLastPathSegment(); |
| 57 | Notify.show("正在下載..." + name); |
| 58 | Response response = OkHttp.newCall(action, TAG); |
| 59 | File file = Path.create(new File(Path.download(), name)); |
| 60 | download(file, response.body().byteStream()); |
| 61 | if (file.getName().endsWith(".zip")) FileUtil.unzip(file, Path.download()); |
| 62 | if (file.getName().endsWith(".apk")) FileUtil.openFile(file); |
| 63 | checkCopy(action); |
| 64 | response.close(); |
| 65 | return Result.notify("下載完成"); |
| 66 | } catch (Exception e) { |
| 67 | return Result.notify(e.getMessage()); |
| 68 | } |
| 69 | } |
| 70 | |
| 71 | private void download(File file, InputStream is) throws IOException { |
| 72 | try (BufferedInputStream input = new BufferedInputStream(is); FileOutputStream os = new FileOutputStream(file)) { |
nothing calls this directly
no test coverage detected