feat(AI资源广场): 修复解析SKILL.md内容时,部分情况下会出现乱码的问题

This commit is contained in:
otto 2026-05-28 09:06:16 +08:00
parent 1883e78fcb
commit 6f881dad5c
1 changed files with 7 additions and 6 deletions

View File

@ -22,6 +22,7 @@ import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
import org.apache.commons.compress.archivers.zip.ZipFile;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@ -162,13 +163,13 @@ public class AiResourceParseServiceImpl implements IAiResourceParseService {
}
private String readEntryContent(ZipArchiveInputStream zais) throws IOException {
StringBuilder sb = new StringBuilder();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int len;
while ((len = zais.read(buffer)) > 0) {
sb.append(new String(buffer, 0, len, StandardCharsets.UTF_8));
baos.write(buffer, 0, len);
}
return sb.toString();
return new String(baos.toByteArray(), StandardCharsets.UTF_8);
}
@Override
@ -285,13 +286,13 @@ public class AiResourceParseServiceImpl implements IAiResourceParseService {
private String readZipEntryContent(ZipFile zf, ZipArchiveEntry entry) throws IOException {
try (InputStream is = zf.getInputStream(entry)) {
StringBuilder sb = new StringBuilder();
ByteArrayOutputStream baos = new ByteArrayOutputStream();
byte[] buffer = new byte[4096];
int len;
while ((len = is.read(buffer)) > 0) {
sb.append(new String(buffer, 0, len, StandardCharsets.UTF_8));
baos.write(buffer, 0, len);
}
return sb.toString();
return new String(baos.toByteArray(), StandardCharsets.UTF_8);
}
}