sonarqube质量修复

This commit is contained in:
gaoqr
2024-10-08 16:52:56 +08:00
parent 4fe3cfda62
commit 73b4051641
41 changed files with 151 additions and 4400 deletions
@@ -6,6 +6,7 @@ import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.IOUtils;
import org.springframework.core.io.ByteArrayResource;
import org.springframework.core.io.InputStreamResource;
import org.springframework.http.HttpStatus;
@@ -16,35 +17,20 @@ import javax.annotation.Resource;
import java.io.*;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
import com.jacob.activeX.ActiveXComponent;
import com.jacob.com.Dispatch;
import com.jacob.com.Variant;
import javax.sql.rowset.serial.SerialBlob;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.Blob;
import java.sql.SQLException;
import java.util.Objects;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.net.http.WebSocket;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.nio.channels.FileChannel;
import java.nio.channels.WritableByteChannel;
import java.util.Objects;
import java.util.Random;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
import static org.aspectj.weaver.tools.cache.SimpleCacheFactory.path;
@Service
@Slf4j
public class VoiceServiceImpl implements VoiceService{
@@ -68,7 +54,7 @@ public class VoiceServiceImpl implements VoiceService{
String path = vocieParameters.getPath();
// 设置音频的质量( 越大越好,目前最大好像 22,最小为 4 )
Long quality = vocieParameters.getQuality();;
Long quality = vocieParameters.getQuality();
// 朗读声音大小
Long soundSize = vocieParameters.getSoundSize();
@@ -108,7 +94,7 @@ public class VoiceServiceImpl implements VoiceService{
Dispatch.call(spVoice, "Speak", new Variant(data));
System.out.println("输出语音文件成功!");
log.info("输出语音文件成功!");
return filePath;
@@ -151,7 +137,6 @@ public class VoiceServiceImpl implements VoiceService{
}
byte[] audioBytes = byteArrayOutputStream.toByteArray();
ByteArrayResource byteArrayResource = new ByteArrayResource(audioBytes);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.parseMediaType("audio/mpeg"));
@@ -179,15 +164,14 @@ public class VoiceServiceImpl implements VoiceService{
**/
@Override
public void zipFiles(String fileNames, String zipOutName) throws IOException {
ZipOutputStream zipOutputStream = null;
WritableByteChannel writableByteChannel = null;
ByteBuffer buffer = ByteBuffer.allocate(2048);
try {
zipOutputStream = new ZipOutputStream(new FileOutputStream(zipOutName));
FileChannel fileChannel = null;
try (ZipOutputStream zipOutputStream = new ZipOutputStream(new FileOutputStream(zipOutName))) {
writableByteChannel = Channels.newChannel(zipOutputStream);
File source = new File(fileNames);
zipOutputStream.putNextEntry(new ZipEntry(source.getName()));
FileChannel fileChannel = new FileInputStream(fileNames).getChannel();
fileChannel = new FileInputStream(fileNames).getChannel();
while (fileChannel.read(buffer) != -1) {
//更新缓存区位置
buffer.flip();
@@ -198,14 +182,14 @@ public class VoiceServiceImpl implements VoiceService{
}
fileChannel.close();
System.out.println("文件压缩成功");
log.info("文件压缩成功");
} catch (Exception e) {
log.error("batchZipFiles error fileNames:");
} finally {
zipOutputStream.close();
writableByteChannel.close();
IOUtils.closeQuietly(writableByteChannel);
IOUtils.closeQuietly(fileChannel);
buffer.clear();
}
}
@@ -217,26 +201,26 @@ public class VoiceServiceImpl implements VoiceService{
// 检查文件路径是否为空
if (sourceFile == null || sourceFile.isEmpty()) {
System.out.println("文件路径为空");
log.error("文件路径为空");
}
File file = new File(sourceFile);
// 检查文件是否存在
if (!file.exists()) {
System.out.println("文件不存在:" + sourceFile);
log.error("文件不存在:" + sourceFile);
}
// 检查是否是文件
if (!file.isFile()) {
System.out.println("路径指向的不是文件:" + sourceFile);
log.error("路径指向的不是文件:" + sourceFile);
}
// 尝试删除文件
if (file.delete()) {
System.out.println("文件删除成功:" + sourceFile);
log.error("文件删除成功:" + sourceFile);
} else {
System.out.println("文件删除失败:" + sourceFile);
log.error("文件删除失败:" + sourceFile);
}
}