更新文档&细节调整

This commit is contained in:
陈精华
2020-05-20 06:52:49 +08:00
committed by kl
parent c7318c2b17
commit 26e147b426
6 changed files with 117 additions and 27 deletions

View File

@ -65,7 +65,8 @@ ftp.control.encoding = ${KK_FTP_CONTROL_ENCODING:UTF-8}
#水印内容
#watermark.txt = ${WATERMARK_TXT:凯京科技内部文件严禁外泄}
watermark.txt = ${WATERMARK_TXT:kkFileView文件预览}
#如需取消水印内容设置为空即可watermark.txt = ${WATERMARK_TXT:}
watermark.txt = ${WATERMARK_TXT:}
#水印x轴间隔
watermark.x.space = ${WATERMARK_X_SPACE:10}
#水印y轴间隔

View File

@ -21,7 +21,7 @@ public class URLUtil {
* @return 标准化后的URL字符串
*/
public static String normalize(String url) {
return normalize(url, false);
return normalize(url, false, false);
}
/**
@ -33,10 +33,11 @@ public class URLUtil {
*
* @param url URL字符串
* @param isEncodeBody 是否对URL中body部分的中文和特殊字符做转义不包括http:和/
* @param isEncodeParam 是否对URL中参数部分的中文和特殊字符做转义
* @return 标准化后的URL字符串
* @since 4.4.1
*/
public static String normalize(String url, boolean isEncodeBody) {
public static String normalize(String url, boolean isEncodeBody, boolean isEncodeParam) {
if (StrUtil.isBlank(url)) {
return url;
}
@ -54,7 +55,7 @@ public class URLUtil {
final int paramsSepIndex = StrUtil.indexOf(body, '?');
String params = null;
if (paramsSepIndex > 0) {
params = StrUtil.subSuf(body, paramsSepIndex);
params = StrUtil.subSuf(body, paramsSepIndex + 1);
body = StrUtil.subPre(body, paramsSepIndex);
}
@ -64,6 +65,9 @@ public class URLUtil {
body = body.replace("\\", "/").replaceAll("//+", "/");
if (isEncodeBody) {
body = URLEncoder.DEFAULT.encode(body, StandardCharsets.UTF_8);
if (params != null) {
params = "?" + URLEncoder.DEFAULT.encode(params, StandardCharsets.UTF_8);
}
}
return pre + body + StrUtil.nullToEmpty(params);
}

View File

@ -58,7 +58,7 @@ public class DownloadUtils {
URL url = new URL(urlStr);
OutputStream os = new FileOutputStream(new File(realPath));
if (url.getProtocol() != null && url.getProtocol().toLowerCase().startsWith("http")) {
saveToOutputStreamFormUrl(urlStr, os);
saveToOutputStreamFromUrl(urlStr, os);
} else if (url.getProtocol() != null && "ftp".equals(url.getProtocol().toLowerCase())) {
String ftpUsername = fileUtils.getUrlParameterReg(fileAttribute.getUrl(), URL_PARAM_FTP_USERNAME);
String ftpPassword = fileUtils.getUrlParameterReg(fileAttribute.getUrl(), URL_PARAM_FTP_PASSWORD);
@ -88,12 +88,12 @@ public class DownloadUtils {
}
}
public boolean saveToOutputStreamFormUrl(String urlStr, OutputStream os) throws IOException {
public boolean saveToOutputStreamFromUrl(String urlStr, OutputStream os) throws IOException {
InputStream is = getInputStreamFromUrl(urlStr);
if (is != null) {
copyStream(is, os);
} else {
urlStr = URLUtil.normalize(urlStr, true);
urlStr = URLUtil.normalize(urlStr, true, true);
is = getInputStreamFromUrl(urlStr);
if (is != null) {
copyStream(is, os);

View File

@ -84,7 +84,7 @@ public class OnlinePreviewController {
public void getCorsFile(String urlPath, HttpServletResponse response) {
logger.info("下载跨域pdf文件url{}", urlPath);
try {
downloadUtils.saveToOutputStreamFormUrl(urlPath, response.getOutputStream());
downloadUtils.saveToOutputStreamFromUrl(urlPath, response.getOutputStream());
} catch (IOException e) {
logger.error("下载跨域pdf文件异常url{}", urlPath, e);
}