Commit 0b5beb36 authored by 李秀明's avatar 李秀明

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

parent 93eaef2b
...@@ -17,12 +17,12 @@ import java.util.Map; ...@@ -17,12 +17,12 @@ import java.util.Map;
/** /**
* *
* <pre> * <pre>
* 导出excel表格工具类 * 导出excel表格工具类
* </pre> * </pre>
* *
* *
*/ */
public class ExcelUtil public class ExcelUtil
{ {
...@@ -31,7 +31,7 @@ public class ExcelUtil ...@@ -31,7 +31,7 @@ public class ExcelUtil
private static final String TITLE="title"; private static final String TITLE="title";
/** /**
* *
* <pre> * <pre>
* 根据源数据创建Excel表格 * 根据源数据创建Excel表格
* </pre> * </pre>
...@@ -59,7 +59,7 @@ public class ExcelUtil ...@@ -59,7 +59,7 @@ public class ExcelUtil
style2.setFillForegroundColor((short) 9); style2.setFillForegroundColor((short) 9);
HSSFFont font2 = workbook.createFont(); HSSFFont font2 = workbook.createFont();
style2.setFont(font2); style2.setFont(font2);
for (int i = 0; i < dataList.size(); i++) for (int i = 0; i < dataList.size(); i++)
{ {
...@@ -88,7 +88,7 @@ public class ExcelUtil ...@@ -88,7 +88,7 @@ public class ExcelUtil
} }
public static void createXSSFExcel(String path, String fileName, List<String> headers, List<List<String>> dataList) { public static void createXSSFExcel(String path, String fileName, List<String> headers, List<List<String>> dataList) {
File file = new File(path + "\\" + fileName); File file = new File(path + File.separator + fileName);
if (!file.isDirectory()) { if (!file.isDirectory()) {
file.mkdirs(); file.mkdirs();
} }
...@@ -117,7 +117,7 @@ public class ExcelUtil ...@@ -117,7 +117,7 @@ public class ExcelUtil
style2.setFillForegroundColor((short) 9); style2.setFillForegroundColor((short) 9);
Font font2 = sxssfWorkbook.createFont(); Font font2 = sxssfWorkbook.createFont();
style2.setFont(font2); style2.setFont(font2);
SXSSFRow row = sheet.createRow(0); SXSSFRow row = sheet.createRow(0);
for (int i = 0; i < headers.size(); i++) { for (int i = 0; i < headers.size(); i++) {
SXSSFCell cell = row.createCell(i); SXSSFCell cell = row.createCell(i);
...@@ -142,9 +142,9 @@ public class ExcelUtil ...@@ -142,9 +142,9 @@ public class ExcelUtil
} }
} }
} }
/** /**
* *
* <pre> * <pre>
* 输出表格 * 输出表格
* </pre> * </pre>
...@@ -172,9 +172,9 @@ public class ExcelUtil ...@@ -172,9 +172,9 @@ public class ExcelUtil
e.printStackTrace(); e.printStackTrace();
} }
} }
/** /**
* *
* <pre> * <pre>
* 输出表格 * 输出表格
* </pre> * </pre>
...@@ -193,12 +193,12 @@ public class ExcelUtil ...@@ -193,12 +193,12 @@ public class ExcelUtil
response.setHeader("Content-disposition", response.setHeader("Content-disposition",
"attachment; filename=" + name); "attachment; filename=" + name);
response.setContentType("application/vnd.ms-excel;charset=utf-8"); response.setContentType("application/vnd.ms-excel;charset=utf-8");
int b = 0; int b = 0;
byte[] buffer = new byte[1024*10]; byte[] buffer = new byte[1024*10];
while (b != -1){ while (b != -1){
b = inputStream.read(buffer); b = inputStream.read(buffer);
if (-1 != b) { if (-1 != b) {
output.write(buffer, 0, b); output.write(buffer, 0, b);
} }
} }
output.flush(); output.flush();
...@@ -219,7 +219,7 @@ public class ExcelUtil ...@@ -219,7 +219,7 @@ public class ExcelUtil
} }
/** /**
* *
* <pre> * <pre>
* 创建盘点结果Excel表格数据 * 创建盘点结果Excel表格数据
* </pre> * </pre>
...@@ -311,17 +311,17 @@ public class ExcelUtil ...@@ -311,17 +311,17 @@ public class ExcelUtil
return workbook; return workbook;
} }
private static void setBorderStyle(CellStyle style){ private static void setBorderStyle(CellStyle style){
style.setBorderBottom(BorderStyle.THIN); style.setBorderBottom(BorderStyle.THIN);
style.setBorderLeft(BorderStyle.THIN); style.setBorderLeft(BorderStyle.THIN);
style.setBorderRight(BorderStyle.THIN); style.setBorderRight(BorderStyle.THIN);
style.setBorderTop(BorderStyle.THIN); style.setBorderTop(BorderStyle.THIN);
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
private static void setHSSFCellStyle(CellStyle style){ private static void setHSSFCellStyle(CellStyle style){
style.setLocked(true); style.setLocked(true);
style.setWrapText(true); style.setWrapText(true);
style.setAlignment(HorizontalAlignment.CENTER);// 左右居中 style.setAlignment(HorizontalAlignment.CENTER);// 左右居中
style.setVerticalAlignment(VerticalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER);
...@@ -331,11 +331,11 @@ public class ExcelUtil ...@@ -331,11 +331,11 @@ public class ExcelUtil
style.setBorderRight(BorderStyle.THIN); style.setBorderRight(BorderStyle.THIN);
style.setBorderTop(BorderStyle.THIN); style.setBorderTop(BorderStyle.THIN);
} }
/** /**
* 创建车辆导出Excl,合并表头 * 创建车辆导出Excl,合并表头
* *
* @param carLists * @param carLists
* @return * @return
*/ */
...@@ -472,7 +472,7 @@ public class ExcelUtil ...@@ -472,7 +472,7 @@ public class ExcelUtil
} }
rangelist.forEach(e -> sheet.addMergedRegion(e)); rangelist.forEach(e -> sheet.addMergedRegion(e));
for (int r = 4; r < carLists.size()+4; r++) { for (int r = 4; r < carLists.size()+4; r++) {
r1 = sheet.createRow(r); r1 = sheet.createRow(r);
List<String> list = carLists.get(r-4); List<String> list = carLists.get(r-4);
...@@ -509,7 +509,7 @@ public class ExcelUtil ...@@ -509,7 +509,7 @@ public class ExcelUtil
* @return * @return
*/ */
public static Sheet createProtectiveEquipmentExportExcel( public static Sheet createProtectiveEquipmentExportExcel(
Map<String,List<String>> headers,List<List<String>> contents, Map<String,List<String>> headers,List<List<String>> contents,
String sheetName,Workbook workbook) String sheetName,Workbook workbook)
{ {
Sheet sheet = workbook.createSheet(sheetName); Sheet sheet = workbook.createSheet(sheetName);
...@@ -535,7 +535,7 @@ public class ExcelUtil ...@@ -535,7 +535,7 @@ public class ExcelUtil
firstHeadRow.setHeightInPoints(30); firstHeadRow.setHeightInPoints(30);
int firstHeadSize=headers.get("header1").size(); int firstHeadSize=headers.get("header1").size();
int start=4; int start=4;
for (int i = 0; i < firstHeadSize; i++) for (int i = 0; i < firstHeadSize; i++)
{ {
String[] firstHeadArray=headers.get("header1").get(i).split(":"); String[] firstHeadArray=headers.get("header1").get(i).split(":");
...@@ -543,7 +543,7 @@ public class ExcelUtil ...@@ -543,7 +543,7 @@ public class ExcelUtil
//计算所需合并单元格的坐标 //计算所需合并单元格的坐标
rangelist.add(new CellRangeAddress( rangelist.add(new CellRangeAddress(
1,1,start,start+Integer.valueOf(firstHeadArray[1])-1)); 1,1,start,start+Integer.valueOf(firstHeadArray[1])-1));
for (int j = start; j <= start+Integer.valueOf(firstHeadArray[1])-1; j++) for (int j = start; j <= start+Integer.valueOf(firstHeadArray[1])-1; j++)
{ {
Cell firstHeadCell=firstHeadRow.createCell(j); Cell firstHeadCell=firstHeadRow.createCell(j);
...@@ -552,22 +552,22 @@ public class ExcelUtil ...@@ -552,22 +552,22 @@ public class ExcelUtil
//设置单元格宽度自适应 //设置单元格宽度自适应
} }
start=start+Integer.valueOf(firstHeadArray[1]);//计算下一个标题的单元格起始位置 start=start+Integer.valueOf(firstHeadArray[1]);//计算下一个标题的单元格起始位置
} }
rangelist.forEach(e->{ rangelist.forEach(e->{
sheet.addMergedRegion(e);//合并单元格 sheet.addMergedRegion(e);//合并单元格
setRegionStyle(sheet,e,style2);//添加样式 setRegionStyle(sheet,e,style2);//添加样式
}); });
/**********************二级表头**********************/ /**********************二级表头**********************/
rangelist.clear();// 清空合并单元格集合 rangelist.clear();// 清空合并单元格集合
Row secondHeadRow = sheet.createRow(2); Row secondHeadRow = sheet.createRow(2);
secondHeadRow.setHeightInPoints(120); secondHeadRow.setHeightInPoints(120);
int secondHeadSize=headers.get("header2").size(); int secondHeadSize=headers.get("header2").size();
for (int i = 0; i < secondHeadSize; i++) for (int i = 0; i < secondHeadSize; i++)
{ {
String secondHeadValue=headers.get("header2").get(i); String secondHeadValue=headers.get("header2").get(i);
...@@ -580,23 +580,23 @@ public class ExcelUtil ...@@ -580,23 +580,23 @@ public class ExcelUtil
firstHeadCell.setCellValue(secondHeadValue); firstHeadCell.setCellValue(secondHeadValue);
// sheet.setColumnWidth(i, secondHeadValue.getBytes().length*256);//设置单元格宽度自适应 // sheet.setColumnWidth(i, secondHeadValue.getBytes().length*256);//设置单元格宽度自适应
rangelist.add(new CellRangeAddress(1, 2, i,i)); rangelist.add(new CellRangeAddress(1, 2, i,i));
}else }else
{ {
sheet.setColumnWidth(i, 1536);//设置单元格宽度为两个中文宽度 sheet.setColumnWidth(i, 1536);//设置单元格宽度为两个中文宽度
} }
} }
rangelist.forEach(e->{ rangelist.forEach(e->{
sheet.addMergedRegion(e);//合并单元格 sheet.addMergedRegion(e);//合并单元格
setRegionStyle(sheet,e,style2);//添加样式 setRegionStyle(sheet,e,style2);//添加样式
}); });
/**********************填充表格内容第一行**********************/ /**********************填充表格内容第一行**********************/
Row startContentRow = sheet.createRow(3); Row startContentRow = sheet.createRow(3);
setFirstContentValue(headers.get("startContent"), style, startContentRow); setFirstContentValue(headers.get("startContent"), style, startContentRow);
sheet.addMergedRegion(new CellRangeAddress(3,3,0,1)); sheet.addMergedRegion(new CellRangeAddress(3,3,0,1));
/**********************填充表格内容中间**********************/ /**********************填充表格内容中间**********************/
setMidContentValue(contents, style, sheet, 4); setMidContentValue(contents, style, sheet, 4);
...@@ -615,7 +615,7 @@ public class ExcelUtil ...@@ -615,7 +615,7 @@ public class ExcelUtil
} }
return sheet; return sheet;
} }
/** /**
* <pre> * <pre>
* 消防车辆Excel导出格式(表头只有装备定义名称的均可通用) * 消防车辆Excel导出格式(表头只有装备定义名称的均可通用)
...@@ -626,39 +626,39 @@ public class ExcelUtil ...@@ -626,39 +626,39 @@ public class ExcelUtil
* @return * @return
*/ */
public static Sheet createFireVehicleExportExcel( public static Sheet createFireVehicleExportExcel(
Map<String,List<String>> headers,List<List<String>> contents, Map<String,List<String>> headers,List<List<String>> contents,
String sheetName,Workbook workbook) String sheetName,Workbook workbook)
{ {
Sheet sheet = workbook.createSheet(sheetName); Sheet sheet = workbook.createSheet(sheetName);
try try
{ {
sheet.setDefaultColumnWidth((short) 15); sheet.setDefaultColumnWidth((short) 15);
/*************************表格内容格式*********************/ /*************************表格内容格式*********************/
CellStyle style = getContentStyle(workbook); CellStyle style = getContentStyle(workbook);
/*************************表头格式**********************/ /*************************表头格式**********************/
CellStyle style2 = getHeaderStyle(workbook); CellStyle style2 = getHeaderStyle(workbook);
/*************************标题格式**********************/ /*************************标题格式**********************/
CellStyle style3 = getTitleStyle(workbook); CellStyle style3 = getTitleStyle(workbook);
/********************填充标题行************************/ /********************填充标题行************************/
setTitleValue(headers.get(TITLE), style3, sheet); setTitleValue(headers.get(TITLE), style3, sheet);
/**********************填充表头**********************/ /**********************填充表头**********************/
Row headRow = sheet.createRow(1); Row headRow = sheet.createRow(1);
headRow.setHeightInPoints(120); headRow.setHeightInPoints(120);
setContentValue(headers.get("header"),style2,headRow); setContentValue(headers.get("header"),style2,headRow);
/**********************填充表格内容第一行**********************/ /**********************填充表格内容第一行**********************/
Row startContentRow = sheet.createRow(2); Row startContentRow = sheet.createRow(2);
setFirstContentValue(headers.get("startContent"), style, startContentRow); setFirstContentValue(headers.get("startContent"), style, startContentRow);
sheet.addMergedRegion(new CellRangeAddress(2,2,0,1)); sheet.addMergedRegion(new CellRangeAddress(2,2,0,1));
/**********************填充表格内容中间**********************/ /**********************填充表格内容中间**********************/
setMidContentValue(contents, style, sheet, 3); setMidContentValue(contents, style, sheet, 3);
/**********************填充表格内容最后一行**********************/ /**********************填充表格内容最后一行**********************/
int titleSize =Integer.valueOf(headers.get(TITLE).get(0).split(":")[1]); int titleSize =Integer.valueOf(headers.get(TITLE).get(0).split(":")[1]);
Row endContentRow = sheet.createRow(3+contents.size()); Row endContentRow = sheet.createRow(3+contents.size());
...@@ -674,9 +674,9 @@ public class ExcelUtil ...@@ -674,9 +674,9 @@ public class ExcelUtil
} }
return sheet; return sheet;
} }
/** /**
* *
* <pre> * <pre>
* 设置合并后的单元格格式 * 设置合并后的单元格格式
* </pre> * </pre>
...@@ -685,7 +685,7 @@ public class ExcelUtil ...@@ -685,7 +685,7 @@ public class ExcelUtil
* @param region * @param region
* @param cs * @param cs
*/ */
public static void setRegionStyle(Sheet sheet, CellRangeAddress region,CellStyle cs) public static void setRegionStyle(Sheet sheet, CellRangeAddress region,CellStyle cs)
{ {
for (int i = region.getFirstRow(); i <= region.getLastRow(); i++) { for (int i = region.getFirstRow(); i <= region.getLastRow(); i++) {
...@@ -703,9 +703,9 @@ public class ExcelUtil ...@@ -703,9 +703,9 @@ public class ExcelUtil
} }
} }
} }
/** /**
* *
* <pre> * <pre>
* 表格内容格式 * 表格内容格式
* </pre> * </pre>
...@@ -723,12 +723,12 @@ public class ExcelUtil ...@@ -723,12 +723,12 @@ public class ExcelUtil
style.setAlignment(HorizontalAlignment.CENTER); style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER);
setBorderStyle(style); setBorderStyle(style);
return style; return style;
} }
/** /**
* *
* <pre> * <pre>
* 最后一行内容格式 * 最后一行内容格式
* </pre> * </pre>
...@@ -744,12 +744,12 @@ public class ExcelUtil ...@@ -744,12 +744,12 @@ public class ExcelUtil
style.setFont(font); style.setFont(font);
style.setAlignment(HorizontalAlignment.LEFT); style.setAlignment(HorizontalAlignment.LEFT);
style.setVerticalAlignment(VerticalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER);
return style; return style;
} }
/** /**
* *
* <pre> * <pre>
* 表头格式 * 表头格式
* </pre> * </pre>
...@@ -770,12 +770,12 @@ public class ExcelUtil ...@@ -770,12 +770,12 @@ public class ExcelUtil
style.setAlignment(HorizontalAlignment.CENTER); style.setAlignment(HorizontalAlignment.CENTER);
style.setVerticalAlignment(VerticalAlignment.CENTER); style.setVerticalAlignment(VerticalAlignment.CENTER);
setBorderStyle(style); setBorderStyle(style);
return style; return style;
} }
/** /**
* *
* <pre> * <pre>
* 标题格式 * 标题格式
* </pre> * </pre>
...@@ -798,9 +798,9 @@ public class ExcelUtil ...@@ -798,9 +798,9 @@ public class ExcelUtil
return style; return style;
} }
/** /**
* *
* <pre> * <pre>
* 填充标题行内容 * 填充标题行内容
* </pre> * </pre>
...@@ -816,16 +816,16 @@ public class ExcelUtil ...@@ -816,16 +816,16 @@ public class ExcelUtil
String[] titleArray=datas.get(0).split(":"); String[] titleArray=datas.get(0).split(":");
String titleValue =titleArray[0]; String titleValue =titleArray[0];
int titleSize =Integer.valueOf(titleArray[1]); int titleSize =Integer.valueOf(titleArray[1]);
sheet.addMergedRegion(new CellRangeAddress(0, 0, 0,titleSize-1)); sheet.addMergedRegion(new CellRangeAddress(0, 0, 0,titleSize-1));
titleCell.setCellValue(titleValue); titleCell.setCellValue(titleValue);
titleCell.setCellStyle(style); titleCell.setCellStyle(style);
titleRow.setHeightInPoints(40); titleRow.setHeightInPoints(40);
titleRow.getCell(0).setCellStyle(style); titleRow.getCell(0).setCellStyle(style);
} }
/** /**
* *
* <pre> * <pre>
* 填充单元格内容(无单元格合并,无数据格式转换) * 填充单元格内容(无单元格合并,无数据格式转换)
* </pre> * </pre>
...@@ -849,9 +849,9 @@ public class ExcelUtil ...@@ -849,9 +849,9 @@ public class ExcelUtil
} }
} }
} }
/** /**
* *
* <pre> * <pre>
* 填充表格内容第一行数据(第4列开始转换为Double数据类型) * 填充表格内容第一行数据(第4列开始转换为Double数据类型)
* </pre> * </pre>
...@@ -878,9 +878,9 @@ public class ExcelUtil ...@@ -878,9 +878,9 @@ public class ExcelUtil
} }
} }
} }
/** /**
* *
* <pre> * <pre>
* 填充表格中间内容多行数据(第4列开始转换为Double数据类型) * 填充表格中间内容多行数据(第4列开始转换为Double数据类型)
* </pre> * </pre>
...@@ -915,9 +915,9 @@ public class ExcelUtil ...@@ -915,9 +915,9 @@ public class ExcelUtil
} }
} }
} }
} }
\ No newline at end of file
...@@ -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
......
...@@ -24,7 +24,7 @@ public class WordConverterUtils { ...@@ -24,7 +24,7 @@ public class WordConverterUtils {
/** /**
* 图片存储相对文档路径 * 图片存储相对文档路径
*/ */
private static String imgPath = "\\image\\"; private static String imgPath = File.separator + "image" + File.separator;
/** /**
* word文档转html文档 * word文档转html文档
......
...@@ -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
......
...@@ -5,7 +5,6 @@ import org.slf4j.LoggerFactory; ...@@ -5,7 +5,6 @@ import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async; import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import java.io.File;
import java.io.FileInputStream; import java.io.FileInputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.net.*; import java.net.*;
...@@ -20,9 +19,9 @@ import static com.yeejoin.amos.boot.module.jcs.biz.audioToText.util.SpeechTransc ...@@ -20,9 +19,9 @@ import static com.yeejoin.amos.boot.module.jcs.biz.audioToText.util.SpeechTransc
public class SocketClient { public class SocketClient {
private static final Logger logger = LoggerFactory.getLogger(SocketClient.class); private static final Logger logger = LoggerFactory.getLogger(SocketClient.class);
private static final String[] testFilePath = { private static final String[] testFilePath = {
"C:\\Users\\DELL\\Desktop\\yuyin\\out1.pcm", // * 此处写的文件路径地址不要提交到git, 国网电科院SCA扫描会报告为漏洞: 存在“便携性缺陷”
"C:\\Users\\DELL\\Desktop\\yuyin\\out.pcm",
}; };
private static final String filePath = ""; // * 此处写的文件路径地址不要提交到git, 国网电科院SCA扫描会报告为漏洞: 存在“便携性缺陷”
public static void main(String[] args) throws SocketException { public static void main(String[] args) throws SocketException {
SocketClient socketClient = new SocketClient(); SocketClient socketClient = new SocketClient();
...@@ -35,15 +34,15 @@ public class SocketClient { ...@@ -35,15 +34,15 @@ public class SocketClient {
if (type >= testFilePath.length) type -= 1; if (type >= testFilePath.length) type -= 1;
try (DatagramSocket datagramSocket = new DatagramSocket(); try (DatagramSocket datagramSocket = new DatagramSocket();
FileInputStream fis = new FileInputStream(new File("C:\\Users\\DELL\\Desktop\\ffmpeg-4.4-full_build-shared\\bin\\out.pcm"));) { FileInputStream fis = new FileInputStream(filePath);) {
byte[] b = new byte[1280]; byte[] b = new byte[1280];
int len; int len;
while ((len = fis.read(b)) > 0) { while ((len = fis.read(b)) > 0) {
String logs= String.format("send data pack length: %s",len); String logs = String.format("send data pack length: %s", len);
logger.error( logs); logger.error(logs);
datagramSocket.send(new DatagramPacket(b, b.length,InetAddress.getLocalHost(), port)); datagramSocket.send(new DatagramPacket(b, b.length, InetAddress.getLocalHost(), port));
int deltaSleep = getSleepDelta(len, 16000); int deltaSleep = getSleepDelta(len, 16000);
Thread.sleep(deltaSleep); Thread.sleep(deltaSleep);
TimeUnit.MILLISECONDS.sleep(100); TimeUnit.MILLISECONDS.sleep(100);
...@@ -60,17 +59,14 @@ public class SocketClient { ...@@ -60,17 +59,14 @@ public class SocketClient {
if (type >= testFilePath.length) type -= 1; if (type >= testFilePath.length) type -= 1;
try (Socket socket = new Socket(); try (Socket socket = new Socket();
FileInputStream fis = new FileInputStream(new File(testFilePath[type]));) { FileInputStream fis = new FileInputStream(testFilePath[type]);) {
socket.connect(new InetSocketAddress(InetAddress.getLocalHost().getHostAddress(), port)); socket.connect(new InetSocketAddress(InetAddress.getLocalHost().getHostAddress(), port));
OutputStream outputStream = socket.getOutputStream(); OutputStream outputStream = socket.getOutputStream();
byte[] b = new byte[4096]; byte[] b = new byte[4096];
int len; int len;
while ((len = fis.read(b)) > 0) { while ((len = fis.read(b)) > 0) {
String logs = String.format("send data pack length: %s", len);
logger.error(logs);
String logs= String.format("send data pack length: %s",len);
logger.error( logs);
outputStream.write(b); outputStream.write(b);
TimeUnit.MILLISECONDS.sleep(200); TimeUnit.MILLISECONDS.sleep(200);
} }
......
...@@ -220,7 +220,7 @@ public class SpeechTranscriberDemo { ...@@ -220,7 +220,7 @@ public class SpeechTranscriberDemo {
System.exit(-1); System.exit(-1);
}*/ }*/
//本案例使用本地文件模拟发送实时流数据。您在实际使用时,可以实时采集或接收语音流并发送到ASR服务端。 //本案例使用本地文件模拟发送实时流数据。您在实际使用时,可以实时采集或接收语音流并发送到ASR服务端。
String filepath = "C:\\Users\\DELL\\Desktop\\ffmpeg-4.4-full_build-shared\\bin\\1839.pcm"; String filepath = ""; // * 此处写的文件路径地址不要提交到git, 国网电科院SCA扫描会报告为漏洞: 存在“便携性缺陷”
SpeechTranscriberDemo demo = new SpeechTranscriberDemo(appKey, id, secret, url); SpeechTranscriberDemo demo = new SpeechTranscriberDemo(appKey, id, secret, url);
demo.process(filepath); demo.process(filepath);
demo.shutdown(); demo.shutdown();
......
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