|
@@ -21,13 +21,13 @@ import com.qmth.teachcloud.common.enums.*;
|
|
import com.qmth.teachcloud.common.service.*;
|
|
import com.qmth.teachcloud.common.service.*;
|
|
import com.qmth.teachcloud.common.util.*;
|
|
import com.qmth.teachcloud.common.util.*;
|
|
import org.apache.commons.io.FileUtils;
|
|
import org.apache.commons.io.FileUtils;
|
|
-import org.apache.commons.io.IOUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.util.CollectionUtils;
|
|
import org.springframework.util.CollectionUtils;
|
|
|
|
+import org.springframework.util.FileCopyUtils;
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
import org.springframework.util.LinkedMultiValueMap;
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
import javax.annotation.Resource;
|
|
@@ -544,10 +544,13 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
|
|
|
|
if (filePath.endsWith(SystemConstant.HTML_PREFIX) || filePath.endsWith(SystemConstant.FTL_PREFIX)) {
|
|
if (filePath.endsWith(SystemConstant.HTML_PREFIX) || filePath.endsWith(SystemConstant.FTL_PREFIX)) {
|
|
StringBuffer sb = new StringBuffer();
|
|
StringBuffer sb = new StringBuffer();
|
|
|
|
+ File fileTemp = null;
|
|
|
|
+ InputStream fis = null;
|
|
try {
|
|
try {
|
|
- InputStream fis = null;
|
|
|
|
|
|
+ fileTemp = SystemConstant.getFileTempVar(SystemConstant.HTML_PREFIX);
|
|
if (type.equals(SystemConstant.OSS)) {
|
|
if (type.equals(SystemConstant.OSS)) {
|
|
fis = fileStoreUtil.ossDownloadIs(filePath, uploadType.getFssType());
|
|
fis = fileStoreUtil.ossDownloadIs(filePath, uploadType.getFssType());
|
|
|
|
+ FileUtils.copyInputStreamToFile(fis, fileTemp);
|
|
} else {
|
|
} else {
|
|
File file = null;
|
|
File file = null;
|
|
if (dictionaryConfig.fssPrivateDomain().getConfig().startsWith(SystemConstant.START_PARENT) || dictionaryConfig.fssPublicDomain().getConfig().startsWith(SystemConstant.START_PARENT)) {
|
|
if (dictionaryConfig.fssPrivateDomain().getConfig().startsWith(SystemConstant.START_PARENT) || dictionaryConfig.fssPublicDomain().getConfig().startsWith(SystemConstant.START_PARENT)) {
|
|
@@ -555,15 +558,24 @@ public class TeachcloudCommonServiceImpl implements TeachcloudCommonService {
|
|
} else {
|
|
} else {
|
|
file = new File(filePath);
|
|
file = new File(filePath);
|
|
}
|
|
}
|
|
- fis = new FileInputStream(file);
|
|
|
|
|
|
+ FileCopyUtils.copy(file, fileTemp);
|
|
|
|
+ }
|
|
|
|
+ if (Objects.nonNull(fileTemp)) {
|
|
|
|
+ sb.append(FileUtils.readFileToString(fileTemp, StandardCharsets.UTF_8));
|
|
}
|
|
}
|
|
- ByteArrayOutputStream ou = new ByteArrayOutputStream();
|
|
|
|
- IOUtils.copy(fis, ou);
|
|
|
|
- sb.append(new String(ou.toByteArray(), StandardCharsets.UTF_8));
|
|
|
|
- } catch (IOException e) {
|
|
|
|
- throw ExceptionResultEnum.ERROR.exception("文件读取异常");
|
|
|
|
} catch (Exception e) {
|
|
} catch (Exception e) {
|
|
log.error(SystemConstant.LOG_ERROR, e);
|
|
log.error(SystemConstant.LOG_ERROR, e);
|
|
|
|
+ } finally {
|
|
|
|
+ if (Objects.nonNull(fis)) {
|
|
|
|
+ try {
|
|
|
|
+ fis.close();
|
|
|
|
+ } catch (IOException e) {
|
|
|
|
+ e.printStackTrace();
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ if (Objects.nonNull(fileTemp)) {
|
|
|
|
+ fileTemp.delete();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
return sb.toString();
|
|
return sb.toString();
|
|
}
|
|
}
|