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

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

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