Commit 040807a7 authored by 张森's avatar 张森

Unreleased Resource: Streams(未出租的资源:流) 问题修复

parent ae7a15a5
package com.yeejoin.equipmanage.common.utils;
import org.apache.commons.io.FilenameUtils;
import org.apache.cxf.helpers.FileUtils;
import org.apache.poi.hwpf.HWPFDocument;
import org.apache.poi.hwpf.converter.PicturesManager;
......@@ -12,7 +13,6 @@ import org.apache.poi.xwpf.converter.core.IXWPFConverter;
import org.apache.poi.xwpf.converter.xhtml.XHTMLConverter;
import org.apache.poi.xwpf.converter.xhtml.XHTMLOptions;
import org.apache.poi.xwpf.usermodel.XWPFDocument;
import org.apache.tika.io.FilenameUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.w3c.dom.Document;
......@@ -194,18 +194,15 @@ public class WordHtml implements AbstractHtml {
public static void xml2Ttml(String docPath, String xsltPath, String hrmlPath) {
FileInputStream fis = null;
FileInputStream fis1 = null;
try {
try (
//创建XML的文件输入流
fis = new FileInputStream(FilenameUtils.normalize(docPath));
Source source = new StreamSource(fis);
FileInputStream fis = new FileInputStream(org.apache.commons.io.FilenameUtils.normalize(docPath));
//创建XSL文件的输入流
fis1 = new FileInputStream(FilenameUtils.normalize(xsltPath));
FileInputStream fis1 = new FileInputStream(FilenameUtils.normalize(xsltPath));
PrintStream stm = new PrintStream(hrmlPath);
) {
Source source = new StreamSource(fis);
Source template = new StreamSource(fis1);
PrintStream stm = new PrintStream(new File(hrmlPath));
//讲转换后的结果输出到 stm 中即 F:\123.html
Result result = new StreamResult(stm);
//根据XSL文件创建准个转换对象
......@@ -214,24 +211,9 @@ public class WordHtml implements AbstractHtml {
Transformer transformer = transformerFactory.newTransformer(template);
//处理xml进行交换
transformer.transform(source, result);
} catch (FileNotFoundException e) {
} catch (TransformerException | IOException e) {
e.printStackTrace();
} catch (TransformerException e) {
e.printStackTrace();
} finally {
//关闭文件流
try {
if (null != fis1) {
fis1.close();
}
if (null != fis) {
fis.close();
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
......@@ -191,25 +191,22 @@ public class WordHtml implements AbstractHtml {
}
public static void xml2Ttml(String docPath, String xsltPath, String hrmlPath){
FileInputStream fis= null;
FileInputStream fis1= null;
try {
public static void xml2Ttml(String docPath, String xsltPath, String hrmlPath) {
try (
//创建XML的文件输入流
fis = new FileInputStream(FilenameUtils.normalize(docPath));
Source source=new StreamSource(fis);
FileInputStream fis = new FileInputStream(FilenameUtils.normalize(docPath));
//创建XSL文件的输入流
fis1 = new FileInputStream(FilenameUtils.normalize(xsltPath));
Source template=new StreamSource(fis1);
PrintStream stm=new PrintStream(hrmlPath);
FileInputStream fis1 = new FileInputStream(FilenameUtils.normalize(xsltPath));
PrintStream stm = new PrintStream(hrmlPath);
) {
Source source = new StreamSource(fis);
Source template = new StreamSource(fis1);
//讲转换后的结果输出到 stm 中即 F:\123.html
Result result=new StreamResult(stm);
Result result = new StreamResult(stm);
//根据XSL文件创建准个转换对象
TransformerFactory transformerFactory = TransformerFactory.newInstance();
transformerFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
Transformer transformer= transformerFactory.newTransformer(template);
Transformer transformer = transformerFactory.newTransformer(template);
//处理xml进行交换
transformer.transform(source, result);
} catch (TransformerException | IOException e) {
......
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