troyzhxu/okhttps

JDK 8找不到decode方法。java.lang.NoSuchMethodError: java.net.URLDecoder.decode

ZiYangLqm opened this issue · 1 comments

报错截图
image
BUG定位
image

在BUG解决前可以重写resolveFileName方法
image
`builder.downloadHelper(new com.ejlchina.okhttps.DownloadHelper(){

                @Override
                public String resolveFileName(HttpResult result) {
                    String contentDisposition = result.getHeader("Content-Disposition");
                    // 通过 Content-Disposition 获取文件名,这点跟服务器有关,需要灵活变通
                    if (contentDisposition == null || contentDisposition.length() < 1) {
                        String urlPath = result.getTask().getUrl();
                        String urlName = urlPath.substring(urlPath.lastIndexOf("/") + 1);
                        return toFileName(urlName, result);
                    } else {
                        String filename = null;
                        try {
                            filename = URLDecoder.decode(contentDisposition.substring(
                                    contentDisposition.indexOf("filename=") + 9), "UTF-8");
                        } catch (UnsupportedEncodingException e) {
                            e.printStackTrace();
                        }
                        // 有些文件名会被包含在""里面,所以要去掉,不然无法读取文件后缀
                        return filename.replaceAll("\"", "");
                    }
                }
            }).build();`

已在 v3.4.3 中修复