main
parent
9535d94676
commit
7f274fbedf
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module version="4">
|
||||
<component name="SonarLintModuleSettings">
|
||||
<option name="uniqueId" value="264fc521-6339-4766-8a04-953c6c1bd377" />
|
||||
</component>
|
||||
</module>
|
||||
@ -0,0 +1,14 @@
|
||||
package com.nmgs.entity;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @author: shuguang
|
||||
* @date: 2023年08月14日 10:41
|
||||
* @description: 费率下传--9001
|
||||
*/
|
||||
@Data
|
||||
public class PriceLib {
|
||||
private String idx;
|
||||
private String begDate;
|
||||
}
|
||||
@ -0,0 +1,30 @@
|
||||
package com.nmgs.test;
|
||||
|
||||
import com.nmgs.entity.PriceLib;
|
||||
import com.nmgs.util.DatabaseUtil;
|
||||
import com.nmgs.util.ZlibUtil;
|
||||
|
||||
|
||||
/**
|
||||
* @author: shuguang
|
||||
* @date: 2025年01月15日 10:35
|
||||
* @description:
|
||||
*/
|
||||
public class sqbToZlibTest {
|
||||
public static void main(String[] args) {
|
||||
String sqbFilePath = "D:\\桌面\\PriceLib.sqb";
|
||||
// 指定输出目录
|
||||
String outputDirectory = "D:\\桌面";
|
||||
//文件前缀
|
||||
String filePrefix = "SQB_PRICELIB";
|
||||
|
||||
String sqbUrl = "jdbc:sqlite:" + sqbFilePath;
|
||||
PriceLib priceLib = DatabaseUtil.selectPriceLib("org.sqlite.JDBC", sqbUrl, "SELECT IDX,BEGDATE FROM idx_table");
|
||||
String idx = priceLib.getIdx();
|
||||
|
||||
ZlibUtil.compressPriceSQBToZLIBWithMD5(sqbFilePath, outputDirectory, filePrefix, idx);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
@ -0,0 +1,88 @@
|
||||
package com.nmgs.util;
|
||||
|
||||
import com.nmgs.enumeration.MessageEnum;
|
||||
import com.nmgs.exception.PPException;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.security.MessageDigest;
|
||||
import java.time.LocalDateTime;
|
||||
import java.time.format.DateTimeFormatter;
|
||||
import java.util.zip.Deflater;
|
||||
import java.util.zip.DeflaterOutputStream;
|
||||
|
||||
/**
|
||||
* @author: shuguang
|
||||
* @date: 2025年01月15日 14:42
|
||||
* @description:
|
||||
*/
|
||||
@Slf4j
|
||||
public class ZlibUtil {
|
||||
|
||||
public static void compressPriceSQBToZLIBWithMD5(String sqbFilePath, String outputDirectory, String filePrefix, String idx) {
|
||||
try {
|
||||
// 生成当前时间字符串
|
||||
String formattedTime = getFormattedTime();
|
||||
// 临时生成的 ZLIB 文件路径
|
||||
String tempZlibFileName = filePrefix + "temp_" + formattedTime + "_" + idx + ".ZLIB";
|
||||
String tempZlibFilePath = outputDirectory + File.separator + tempZlibFileName;
|
||||
|
||||
// 压缩文件
|
||||
compressFile(sqbFilePath, tempZlibFilePath);
|
||||
|
||||
// 生成临时 ZLIB 文件的 MD5 值
|
||||
String md5 = getFileMD5(tempZlibFilePath);
|
||||
// 生成最终的文件名
|
||||
String finalZlibFileName = filePrefix + "_" + formattedTime + "_" + idx + "_" + md5 + ".ZLIB";
|
||||
String finalZlibFilePath = outputDirectory + File.separator + finalZlibFileName;
|
||||
|
||||
// 重命名临时文件
|
||||
new File(tempZlibFilePath).renameTo(new File(finalZlibFilePath));
|
||||
|
||||
log.info("文件压缩完成,文件全路径为: {}", finalZlibFilePath);
|
||||
} catch (Exception e) {
|
||||
log.error("文件压缩失败{}", e.getMessage(), e);
|
||||
throw new PPException(MessageEnum.文件压缩失败失败.getCode(), MessageEnum.文件压缩失败失败.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
public static void compressFile(String sourceFilePath, String destFilePath) throws Exception {
|
||||
try (InputStream in = new FileInputStream(sourceFilePath);
|
||||
OutputStream out = new FileOutputStream(destFilePath);
|
||||
DeflaterOutputStream deflaterOutputStream = new DeflaterOutputStream(out, new Deflater(Deflater.BEST_COMPRESSION))) {
|
||||
byte[] buffer = new byte[1024];
|
||||
int bytesRead;
|
||||
while ((bytesRead = in.read(buffer)) != -1) {
|
||||
deflaterOutputStream.write(buffer, 0, bytesRead);
|
||||
}
|
||||
deflaterOutputStream.finish();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFileMD5(String filePath) throws Exception {
|
||||
MessageDigest md = MessageDigest.getInstance("MD5");
|
||||
try (FileInputStream fis = new FileInputStream(filePath)) {
|
||||
byte[] buffer = new byte[1024];
|
||||
int numRead;
|
||||
while ((numRead = fis.read(buffer)) != -1) {
|
||||
md.update(buffer, 0, numRead);
|
||||
}
|
||||
byte[] md5Bytes = md.digest();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
for (byte b : md5Bytes) {
|
||||
sb.append(String.format("%02x", b));
|
||||
}
|
||||
return sb.toString();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getFormattedTime() {
|
||||
LocalDateTime currentTime = LocalDateTime.now();
|
||||
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMddHHmmss");
|
||||
return currentTime.format(formatter);
|
||||
}
|
||||
}
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue