Commit 7e23a914 authored by 李秀明's avatar 李秀明

fix: 使用硬编码文件分隔符会导致可移植性问题

parent dcef3c7c
package com.yeejoin.amos.fas.business.util; package com.yeejoin.amos.fas.business.util;
import org.apache.commons.lang3.StringUtils;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
...@@ -15,6 +16,9 @@ import java.io.InputStream; ...@@ -15,6 +16,9 @@ import java.io.InputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.URL; import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.List; import java.util.List;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream; import java.util.zip.ZipOutputStream;
...@@ -44,8 +48,8 @@ public class FileUtils { ...@@ -44,8 +48,8 @@ public class FileUtils {
OutputStream out = null; OutputStream out = null;
BufferedInputStream br = null; BufferedInputStream br = null;
try { try {
String fileName = new String(zipname.getBytes("UTF-8"), "iso-8859-1"); String fileName = new String(zipname.getBytes(StandardCharsets.UTF_8), StandardCharsets.ISO_8859_1);
br = new BufferedInputStream(new FileInputStream(zippath)); br = new BufferedInputStream(Files.newInputStream(Paths.get(zippath)));
byte[] buf = new byte[1024]; byte[] buf = new byte[1024];
int len = 0; int len = 0;
response.reset(); response.reset();
...@@ -81,7 +85,13 @@ public class FileUtils { ...@@ -81,7 +85,13 @@ public class FileUtils {
ZipOutputStream zos = null; ZipOutputStream zos = null;
// 临时目录 // 临时目录
String path = System.getProperty("java.io.tmpdir") + fileName; String tmpdir = System.getProperty("java.io.tmpdir");
if (StringUtils.isNotBlank(tmpdir) && !tmpdir.endsWith(File.separator)) {
tmpdir += File.separator;
} else if (StringUtils.isBlank(tmpdir)){
tmpdir = "";
}
String path = tmpdir + fileName;
try { try {
File zipFile = new File(path); File zipFile = new File(path);
zipFile.deleteOnExit(); zipFile.deleteOnExit();
......
...@@ -16,7 +16,7 @@ import java.io.*; ...@@ -16,7 +16,7 @@ import java.io.*;
/** /**
* 文档转换工具 * 文档转换工具
* *
* @date * @date
* @author nihuanshan * @author nihuanshan
* *
...@@ -26,11 +26,11 @@ public class WordConverterUtils { ...@@ -26,11 +26,11 @@ public class WordConverterUtils {
/** /**
* 图片存储相对文档路径 * 图片存储相对文档路径
*/ */
private static String imgPath = "\\image\\"; private static String imgPath = File.separator + "image" + File.separator;
/** /**
* word文档转html文档 * word文档转html文档
* *
* @author: nihuanshan * @author: nihuanshan
* @date: 2018年12月6日 下午2:55:32 * @date: 2018年12月6日 下午2:55:32
* @param srcFile 原文档 * @param srcFile 原文档
...@@ -50,7 +50,7 @@ public class WordConverterUtils { ...@@ -50,7 +50,7 @@ public class WordConverterUtils {
} }
} }
} }
/** /**
* word转html字符串 * word转html字符串
* @param srcFile * @param srcFile
...@@ -69,7 +69,7 @@ public class WordConverterUtils { ...@@ -69,7 +69,7 @@ public class WordConverterUtils {
/** /**
* .doc文档转换成html * .doc文档转换成html
* *
* @author: nihuanshan * @author: nihuanshan
* @date: 2018年12月6日 下午2:53:43 * @date: 2018年12月6日 下午2:53:43
* @param srcFile * @param srcFile
...@@ -114,7 +114,7 @@ public class WordConverterUtils { ...@@ -114,7 +114,7 @@ public class WordConverterUtils {
} }
} }
/** /**
* doc转htmlString * doc转htmlString
* @param srcFile * @param srcFile
...@@ -156,7 +156,7 @@ public class WordConverterUtils { ...@@ -156,7 +156,7 @@ public class WordConverterUtils {
serializer.setOutputProperty(OutputKeys.METHOD, "html"); serializer.setOutputProperty(OutputKeys.METHOD, "html");
serializer.transform(domSource, streamResult); serializer.transform(domSource, streamResult);
return stringWriter.toString(); return stringWriter.toString();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(); e.printStackTrace();
} }
...@@ -205,9 +205,9 @@ public class WordConverterUtils { ...@@ -205,9 +205,9 @@ public class WordConverterUtils {
} }
} }
/** /**
*docx转htmlString *docx转htmlString
* @param srcFile * @param srcFile
* @param readUrl * @param readUrl
* @return * @return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment