hby100japp功能,语音音量增加

This commit is contained in:
2026-02-06 16:11:38 +08:00
parent f3551be093
commit efad1f5a4b
5 changed files with 165 additions and 10 deletions

View File

@ -4,6 +4,8 @@ import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.multipart.MultipartFile;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.security.MessageDigest;
@ -67,4 +69,32 @@ public class FileHashUtil {
throw new IllegalStateException("算法 " + ALGORITHM + " 不可用", e);
}
}
/**
* 获取文件的哈希值
* // 或者使用特定算法
* String md5Hash = getFileHash(audioFile, "MD5");
* String sha256Hash = getFileHash(audioFile, "SHA-256");
* @param file 文件
* @param algorithm 哈希算法
* @return 文件的哈希值
* @throws Exception 获取文件哈希值时发生的异常
*/
public String getFileHash(File file, String algorithm) throws Exception {
MessageDigest md = MessageDigest.getInstance(algorithm);
try (FileInputStream fis = new FileInputStream(file)) {
byte[] buffer = new byte[8192];
int bytesRead;
while ((bytesRead = fis.read(buffer)) != -1) {
md.update(buffer, 0, bytesRead);
}
}
byte[] hashBytes = md.digest();
StringBuilder sb = new StringBuilder();
for (byte b : hashBytes) {
sb.append(String.format("%02x", b));
}
return sb.toString();
}
}