@xiangyang9999/folib-server-sync-a8be7ecd6f05 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/README.md +57 -2
  2. package/bin/folib-commit-sync.js +70 -0
  3. package/package.json +22 -4
  4. package/payload/INSTRUCTIONS.docx +0 -0
  5. package/payload/changes.patch +1538 -0
  6. package/payload/manifest.json +367 -0
  7. package/payload/manifest.sha256 +41 -0
  8. package/payload/source-files.zip +0 -0
  9. package/source/SECURITY_DEPENDENCY_UPGRADE.md +97 -0
  10. package/source/folib-client/pom.xml +160 -0
  11. package/source/folib-commons/folib-commons-core/pom.xml +297 -0
  12. package/source/folib-commons/folib-commons-core/src/main/java/com/veadan/folib/util/ArchiveExtractionPaths.java +86 -0
  13. package/source/folib-commons/folib-commons-core/src/main/java/com/veadan/folib/util/CompressUtils.java +148 -0
  14. package/source/folib-commons/folib-commons-core/src/test/java/com/veadan/folib/util/ArchiveExtractionPathsTest.java +77 -0
  15. package/source/folib-commons/folib-commons-core/src/test/java/com/veadan/folib/util/CompressUtilsTest.java +286 -0
  16. package/source/folib-commons/folib-commons-io/pom.xml +184 -0
  17. package/source/folib-data-service/pom.xml +259 -0
  18. package/source/folib-data-service/src/test/java/com/veadan/folib/config/hazelcast/HazelcastClusterCompatibilityTest.java +124 -0
  19. package/source/folib-rest-client/pom.xml +166 -0
  20. package/source/folib-security/folib-authentication-registry/pom.xml +117 -0
  21. package/source/folib-security/folib-security-api/pom.xml +416 -0
  22. package/source/folib-storage/folib-storage-layout-providers/folib-storage-debian-layout-provider/src/main/java/com/veadan/folib/indexer/DebianGroupInterceptor.java +251 -0
  23. package/source/folib-storage/folib-storage-layout-providers/folib-storage-debian-layout-provider/src/main/java/com/veadan/folib/indexer/DebianPackagesMetadataIndexer.java +72 -0
  24. package/source/folib-storage/folib-storage-layout-providers/folib-storage-docker-layout-provider/pom.xml +236 -0
  25. package/source/folib-storage/folib-storage-layout-providers/folib-storage-gitlfs-layout-provider/pom.xml +187 -0
  26. package/source/folib-storage/folib-storage-layout-providers/folib-storage-go-layout-provider/pom.xml +180 -0
  27. package/source/folib-storage/folib-storage-layout-providers/folib-storage-helm-layout-provider/pom.xml +125 -0
  28. package/source/folib-storage/folib-storage-layout-providers/folib-storage-huggingface-layout-provider/pom.xml +193 -0
  29. package/source/folib-storage/folib-storage-layout-providers/folib-storage-maven-layout/folib-maven-metadata-api/pom.xml +101 -0
  30. package/source/folib-storage/folib-storage-layout-providers/folib-storage-maven-layout/folib-storage-maven-layout-provider/pom.xml +179 -0
  31. package/source/folib-storage/folib-storage-layout-providers/folib-storage-npm-layout-provider/pom.xml +162 -0
  32. package/source/folib-storage/folib-storage-layout-providers/folib-storage-nuget-layout-provider/pom.xml +155 -0
  33. package/source/folib-storage/folib-storage-layout-providers/folib-storage-p2-layout-provider/pom.xml +116 -0
  34. package/source/folib-storage/folib-storage-layout-providers/folib-storage-php-layout-provider/pom.xml +170 -0
  35. package/source/folib-storage/folib-storage-layout-providers/folib-storage-pypi-layout-provider/pom.xml +278 -0
  36. package/source/folib-storage/folib-storage-layout-providers/folib-storage-raw-layout-provider/pom.xml +183 -0
  37. package/source/folib-web-core/pom.xml +1089 -0
  38. package/source/folib-web-core/src/main/java/com/veadan/folib/app/FolibSpringBootApplication.java +67 -0
  39. package/source/folib-web-core/src/main/java/com/veadan/folib/config/LegacySpringDataWebConfig.java +41 -0
  40. package/source/folib-web-core/src/main/java/com/veadan/folib/config/WebConfig.java +377 -0
  41. package/source/folib-web-core/src/main/java/com/veadan/folib/model/response/OhpmPublishRes.java +16 -0
  42. package/source/folib-web-core/src/main/java/com/veadan/folib/promotion/DockerParsePacketsUtil.java +202 -0
  43. package/source/folib-web-core/src/test/java/com/veadan/folib/config/LegacySpringDataWebConfigTest.java +75 -0
  44. package/source/folib-web-core/src/test/java/com/veadan/folib/config/WebConfigResourceHandlersTest.java +31 -0
  45. package/source/folib-web-core/src/test/java/com/veadan/folib/promotion/DockerArchiveExtractionTest.java +112 -0
  46. package/source/folib-web-core/src/test/java/com/veadan/folib/utils/DependencyCompatibilityTest.java +62 -0
@@ -0,0 +1,148 @@
1
+ package com.veadan.folib.util;
2
+
3
+ import lombok.extern.slf4j.Slf4j;
4
+ import org.apache.commons.compress.archivers.ArchiveEntry;
5
+ import org.apache.commons.compress.archivers.ArchiveInputStream;
6
+ import org.apache.commons.compress.archivers.zip.ZipArchiveInputStream;
7
+ import org.apache.commons.io.IOUtils;
8
+
9
+ import java.io.*;
10
+ import java.nio.charset.Charset;
11
+ import java.nio.charset.StandardCharsets;
12
+ import java.nio.file.Files;
13
+ import java.nio.file.Path;
14
+ import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
15
+ import java.util.Objects;
16
+
17
+ /**
18
+ * @author leipenghui
19
+ * 压缩包工具类(支持大文件ZIP,自动探测编码,解决跨系统文件名乱码)
20
+ **/
21
+ @Slf4j
22
+ public class CompressUtils {
23
+
24
+ // 待探测的ZIP文件名编码列表
25
+ private static final Charset[] DETECT_CHARSETS = {
26
+ StandardCharsets.UTF_8,
27
+ Charset.forName("GBK"),
28
+ Charset.forName("GB2312"),
29
+ StandardCharsets.ISO_8859_1
30
+ };
31
+
32
+ /**
33
+ * 解压zip文件到指定文件夹(保持原有调用方式)
34
+ */
35
+ public static void unzip(String zipFileName, String destDir) throws IOException {
36
+ try (InputStream inputStream = new FileInputStream(zipFileName)) {
37
+ unzip(inputStream, destDir);
38
+ }
39
+ }
40
+
41
+ /**
42
+ * 从输入流中解压zip(适配大文件,临时文件缓存)
43
+ */
44
+ public static void unzip(InputStream inputStream, String destDir) throws IOException {
45
+ // ========== 核心改造:大文件用临时文件缓存,替代内存字节数组 ==========
46
+ Path root = ArchiveExtractionPaths.createRoot(destDir);
47
+ File tempZipFile = null;
48
+ try {
49
+ // 1. 创建临时文件(JVM退出时自动删除,避免磁盘残留)
50
+ tempZipFile = File.createTempFile("zip_temp_", ".zip");
51
+ tempZipFile.deleteOnExit();
52
+
53
+ // 2. 将输入流写入临时文件(流式写入,不占内存)
54
+ try (OutputStream tempOut = new FileOutputStream(tempZipFile)) {
55
+ IOUtils.copy(inputStream, tempOut);
56
+ }
57
+
58
+ // 3. 探测编码:从临时文件读取,而非内存
59
+ Charset targetCharset = detectZipFilenameCharset(tempZipFile);
60
+ log.info("探测到ZIP包内文件名编码:{}", targetCharset.displayName());
61
+
62
+ // 4. 用正确编码解压:从临时文件读取流
63
+ try (
64
+ InputStream tempIn = new FileInputStream(tempZipFile);
65
+ BufferedInputStream bufferedInputStream = new BufferedInputStream(tempIn);
66
+ ArchiveInputStream in = new ZipArchiveInputStream(bufferedInputStream, targetCharset.name())
67
+ ) {
68
+ ArchiveEntry entry = null;
69
+ while (Objects.nonNull(entry = in.getNextEntry())) {
70
+ if (in.canReadEntryData(entry)) {
71
+ if (entry instanceof ZipArchiveEntry && ((ZipArchiveEntry) entry).isUnixSymlink()) {
72
+ throw new IOException("Symbolic links in ZIP archives are not supported");
73
+ }
74
+ if (entry.isDirectory()) {
75
+ ArchiveExtractionPaths.directory(root, entry.getName());
76
+ } else {
77
+ // Stream file contents, but never follow links or write outside the destination.
78
+ try (OutputStream out = ArchiveExtractionPaths.openFile(root, entry.getName())) {
79
+ IOUtils.copy(in, out);
80
+ }
81
+ }
82
+ } else {
83
+ log.info("NotCanReadEntryData [{}]", entry.getName());
84
+ }
85
+ }
86
+ }
87
+ } finally {
88
+ // 手动删除临时文件(保险措施,避免磁盘占用)
89
+ if (tempZipFile != null && tempZipFile.exists()) {
90
+ boolean deleted = tempZipFile.delete();
91
+ if (!deleted) {
92
+ log.warn("临时文件删除失败:{}", tempZipFile.getAbsolutePath());
93
+ }
94
+ }
95
+ }
96
+ }
97
+
98
+ /**
99
+ * 改造编码探测逻辑:从临时文件读取,支持大文件
100
+ */
101
+ private static Charset detectZipFilenameCharset(File zipFile) {
102
+ for (Charset charset : DETECT_CHARSETS) {
103
+ try (
104
+ InputStream tempIn = new FileInputStream(zipFile);
105
+ ZipArchiveInputStream zais = new ZipArchiveInputStream(tempIn, charset.name())
106
+ ) {
107
+ ArchiveEntry entry;
108
+ boolean isMatch = true;
109
+ // 仅检测第一个非空/非目录的文件条目(核心优化,不遍历所有)
110
+ while (Objects.nonNull(entry = zais.getNextEntry())) {
111
+ String entryName = entry.getName();
112
+ // 跳过空条目/目录,只检测文件条目
113
+ if (entryName == null || entryName.isEmpty() || entry.isDirectory()) {
114
+ continue;
115
+ }
116
+ // 检测乱码,有乱码则标记不匹配
117
+ if (containsGarbledChar(entryName)) {
118
+ isMatch = false;
119
+ }
120
+ // 只检测第一个有效条目,直接退出循环
121
+ break;
122
+ }
123
+ if (isMatch) {
124
+ return charset;
125
+ }
126
+ } catch (Exception e) {
127
+ log.debug("编码{}解析失败,尝试下一个", charset.displayName(), e);
128
+ continue;
129
+ }
130
+ }
131
+ // 无匹配编码时默认UTF-8
132
+ return StandardCharsets.UTF_8;
133
+ }
134
+
135
+ /**
136
+ * 判断文件名是否含乱码(保持原有逻辑,仅移除错误的中文反向判断)
137
+ */
138
+ private static boolean containsGarbledChar(String str) {
139
+ if (str == null || str.isEmpty()) {
140
+ return false;
141
+ }
142
+ // 乱码特征:连续问号、UTF-8替换符、不可打印字符
143
+ return str.contains("??")
144
+ || str.contains("\ufffd")
145
+ || str.matches(".*\\?{2,}.*")
146
+ || str.chars().anyMatch(c -> c < 32 && c != 9 && c != 10 && c != 13);
147
+ }
148
+ }
@@ -0,0 +1,77 @@
1
+ package com.veadan.folib.util;
2
+
3
+ import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
4
+ import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
5
+ import org.junit.jupiter.api.Test;
6
+ import org.junit.jupiter.api.io.TempDir;
7
+
8
+ import java.io.IOException;
9
+ import java.io.OutputStream;
10
+ import java.nio.charset.StandardCharsets;
11
+ import java.nio.file.Files;
12
+ import java.nio.file.Path;
13
+
14
+ import static org.junit.jupiter.api.Assertions.*;
15
+
16
+ class ArchiveExtractionPathsTest {
17
+
18
+ @TempDir
19
+ Path temp;
20
+
21
+ @Test
22
+ void nestedFilesAndDirectoryEntriesRemainSupported() throws Exception {
23
+ Path root = ArchiveExtractionPaths.createRoot(temp.resolve("output").toString());
24
+ ArchiveExtractionPaths.directory(root, "./");
25
+ ArchiveExtractionPaths.directory(root, "目录/sub");
26
+ try (OutputStream out = ArchiveExtractionPaths.openFile(root, "目录/sub/test.txt")) {
27
+ out.write("hello".getBytes(StandardCharsets.UTF_8));
28
+ }
29
+ assertEquals("hello", Files.readString(root.resolve("目录/sub/test.txt")));
30
+ try (OutputStream out = ArchiveExtractionPaths.openFile(root, "目录/sub/test.txt")) {
31
+ out.write('x');
32
+ }
33
+ assertEquals("x", Files.readString(root.resolve("目录/sub/test.txt")));
34
+ }
35
+
36
+ @Test
37
+ void rejectsPathsOutsideDestination() throws Exception {
38
+ Path root = ArchiveExtractionPaths.createRoot(temp.resolve("output").toString());
39
+ for (String name : new String[]{"../outside.txt", "..\\outside.txt", "/outside.txt",
40
+ "C:\\outside.txt", "C:outside.txt", "\\\\host\\share\\outside.txt", "dir/../../outside.txt"}) {
41
+ assertThrows(IOException.class, () -> ArchiveExtractionPaths.openFile(root, name), name);
42
+ assertThrows(IOException.class, () -> ArchiveExtractionPaths.directory(root, name), name);
43
+ }
44
+ assertFalse(Files.exists(temp.resolve("outside.txt")));
45
+ }
46
+
47
+ @Test
48
+ void refusesExistingSymbolicLinkParentsAndFiles() throws Exception {
49
+ Path root = ArchiveExtractionPaths.createRoot(temp.resolve("output").toString());
50
+ Path outside = Files.createDirectory(temp.resolve("outside"));
51
+ Path sentinel = Files.writeString(outside.resolve("sentinel.txt"), "unchanged");
52
+ try {
53
+ Files.createSymbolicLink(root.resolve("linked-directory"), outside);
54
+ Files.createSymbolicLink(root.resolve("linked-file"), sentinel);
55
+ } catch (UnsupportedOperationException | IOException e) {
56
+ org.junit.jupiter.api.Assumptions.assumeTrue(false, "Symbolic links unavailable: " + e);
57
+ }
58
+ assertThrows(IOException.class, () -> ArchiveExtractionPaths.openFile(root, "linked-directory/new.txt"));
59
+ assertThrows(IOException.class, () -> ArchiveExtractionPaths.openFile(root, "linked-file"));
60
+ assertFalse(Files.exists(outside.resolve("new.txt")));
61
+ assertEquals("unchanged", Files.readString(sentinel));
62
+ }
63
+
64
+ @Test
65
+ void commonsZipExtractionRejectsOutsideEntry() throws Exception {
66
+ Path archive = temp.resolve("test.zip");
67
+ Path root = Files.createDirectory(temp.resolve("output"));
68
+ try (ZipArchiveOutputStream out = new ZipArchiveOutputStream(archive.toFile())) {
69
+ ZipArchiveEntry entry = new ZipArchiveEntry("../outside.txt");
70
+ out.putArchiveEntry(entry);
71
+ out.write('x');
72
+ out.closeArchiveEntry();
73
+ }
74
+ assertThrows(IOException.class, () -> CompressUtils.unzip(archive.toString(), root.toString()));
75
+ assertFalse(Files.exists(temp.resolve("outside.txt")));
76
+ }
77
+ }
@@ -0,0 +1,286 @@
1
+ package com.veadan.folib.util;
2
+
3
+ import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
4
+ import org.apache.commons.compress.archivers.zip.ZipArchiveOutputStream;
5
+ import org.apache.commons.io.FileUtils;
6
+ import org.junit.jupiter.api.AfterEach;
7
+ import org.junit.jupiter.api.BeforeEach;
8
+ import org.junit.jupiter.api.Test;
9
+
10
+ import java.io.*;
11
+ import java.nio.charset.Charset;
12
+ import java.nio.charset.StandardCharsets;
13
+ import java.nio.file.Files;
14
+ import java.nio.file.Path;
15
+ import java.nio.file.Paths;
16
+
17
+ import static org.junit.jupiter.api.Assertions.*;
18
+
19
+ class CompressUtilsTest {
20
+
21
+ private Path tempDir;
22
+ private Path testZipFile;
23
+ private Path destDir;
24
+ private Path sourceFile;
25
+
26
+ @BeforeEach
27
+ void setUp() throws IOException {
28
+ // 使用系统临时目录,确保目录存在(和您的测试类相同的做法)
29
+ tempDir = Paths.get(System.getProperty("java.io.tmpdir"));
30
+ if (!Files.exists(tempDir)) {
31
+ Files.createDirectories(tempDir);
32
+ }
33
+
34
+ // 创建测试用的ZIP文件
35
+ testZipFile = Files.createTempFile(tempDir, "test", ".zip");
36
+ destDir = Files.createTempDirectory(tempDir, "dest");
37
+ sourceFile = Files.createTempFile(tempDir, "source", ".txt");
38
+
39
+ // 创建源文件内容
40
+ Files.write(sourceFile, "Hello World!".getBytes(StandardCharsets.UTF_8));
41
+ }
42
+
43
+ @AfterEach
44
+ void tearDown() throws IOException {
45
+ // 清理测试文件
46
+ try {
47
+ if (Files.exists(destDir)) {
48
+ FileUtils.deleteDirectory(destDir.toFile());
49
+ }
50
+ if (Files.exists(testZipFile)) {
51
+ Files.delete(testZipFile);
52
+ }
53
+ if (Files.exists(sourceFile)) {
54
+ Files.delete(sourceFile);
55
+ }
56
+ } catch (Exception e) {
57
+ // 忽略删除失败的情况
58
+ }
59
+ }
60
+
61
+ @Test
62
+ void testUnzip_StringString_Success() throws IOException {
63
+ // 准备:创建一个简单的ZIP文件
64
+ createTestZipFile(testZipFile.toString(), "test.txt", "Hello World!");
65
+
66
+ // 执行
67
+ CompressUtils.unzip(testZipFile.toString(), destDir.toString());
68
+
69
+ // 验证
70
+ Path extractedFile = destDir.resolve("test.txt");
71
+ assertTrue(Files.exists(extractedFile));
72
+ assertEquals("Hello World!", Files.readString(extractedFile));
73
+ }
74
+
75
+ @Test
76
+ void testUnzip_InputStreamString_Success() throws IOException {
77
+ // 准备:创建ZIP文件并获取输入流
78
+ createTestZipFile(testZipFile.toString(), "input_stream_test.txt", "Test content from InputStream");
79
+
80
+ try (InputStream inputStream = new FileInputStream(testZipFile.toFile())) {
81
+ // 执行
82
+ CompressUtils.unzip(inputStream, destDir.toString());
83
+ }
84
+
85
+ // 验证
86
+ Path extractedFile = destDir.resolve("input_stream_test.txt");
87
+ assertTrue(Files.exists(extractedFile));
88
+ assertEquals("Test content from InputStream", Files.readString(extractedFile));
89
+ }
90
+
91
+ @Test
92
+ void testUnzip_UTF8Encoding_Success() throws IOException {
93
+ // 准备:创建包含UTF-8中文文件名的ZIP
94
+ String fileName = "测试文件.txt";
95
+ String content = "UTF-8编码测试内容";
96
+ createZipFileWithEncoding(testZipFile.toString(), fileName, content, StandardCharsets.UTF_8);
97
+
98
+ // 执行
99
+ CompressUtils.unzip(testZipFile.toString(), destDir.toString());
100
+
101
+ // 验证
102
+ Path extractedFile = destDir.resolve(fileName);
103
+ assertTrue(Files.exists(extractedFile));
104
+ assertEquals(content, Files.readString(extractedFile, StandardCharsets.UTF_8));
105
+ }
106
+
107
+ @Test
108
+ void testUnzip_GBKEncoding_Success() throws IOException {
109
+ // 准备:创建包含GBK中文文件名的ZIP
110
+ String fileName = "中文测试.txt";
111
+ String content = "GBK编码测试内容";
112
+ createZipFileWithEncoding(testZipFile.toString(), fileName, content, Charset.forName("GBK"));
113
+
114
+ // 执行
115
+ CompressUtils.unzip(testZipFile.toString(), destDir.toString());
116
+
117
+ // 验证
118
+ Path extractedFile = destDir.resolve(fileName);
119
+ assertTrue(Files.exists(extractedFile));
120
+ // 注意:GBK编码的文件内容读取需要特殊处理
121
+ }
122
+
123
+ @Test
124
+ void testUnzip_DirectoryStructure_Preserved() throws IOException {
125
+ // 准备:创建包含目录结构的ZIP文件
126
+ createTestZipWithDirectoryStructure();
127
+
128
+ // 执行
129
+ CompressUtils.unzip(testZipFile.toString(), destDir.toString());
130
+
131
+ // 验证目录结构
132
+ Path nestedFile = destDir.resolve("folder").resolve("subfolder").resolve("test.txt");
133
+ assertTrue(Files.exists(nestedFile));
134
+ assertEquals("Nested folder content", Files.readString(nestedFile));
135
+ }
136
+
137
+ @Test
138
+ void testUnzip_EmptyZip_NoException() throws IOException {
139
+ // 准备:创建空的ZIP文件
140
+ createEmptyZipFile();
141
+
142
+ // 执行 - 应该不抛出异常
143
+ assertDoesNotThrow(() -> CompressUtils.unzip(testZipFile.toString(), destDir.toString()));
144
+
145
+ // 验证目标目录应该存在但为空
146
+ assertTrue(Files.exists(destDir));
147
+ assertEquals(0, Files.list(destDir).count());
148
+ }
149
+
150
+ @Test
151
+ void testUnzip_NonExistentSourceFile_ThrowsIOException() throws IOException {
152
+ Path nonExistentFile = destDir.resolve("missing.zip");
153
+ assertFalse(Files.exists(nonExistentFile));
154
+
155
+ // FileInputStream reports missing input as FileNotFoundException, independent of OS locale.
156
+ assertThrows(FileNotFoundException.class,
157
+ () -> CompressUtils.unzip(nonExistentFile.toString(), destDir.toString()));
158
+ try (java.util.stream.Stream<Path> entries = Files.list(destDir)) {
159
+ assertEquals(0, entries.count());
160
+ }
161
+ }
162
+
163
+ @Test
164
+ void testUnzip_NullDestDir_ThrowsIOException() throws IOException {
165
+ // 准备
166
+ createTestZipFile(testZipFile.toString(), "test.txt", "content");
167
+
168
+ // 执行并验证
169
+ assertThrows(NullPointerException.class,
170
+ () -> CompressUtils.unzip(testZipFile.toString(), null));
171
+ }
172
+
173
+ @Test
174
+ void testContainsGarbledChar_VariousCases() throws Exception {
175
+ // 使用反射调用私有方法
176
+ java.lang.reflect.Method method = CompressUtils.class.getDeclaredMethod(
177
+ "containsGarbledChar", String.class);
178
+ method.setAccessible(true);
179
+
180
+ // 测试正常字符串
181
+ assertFalse((Boolean) method.invoke(null, "normal_string"));
182
+ assertFalse((Boolean) method.invoke(null, "正常中文"));
183
+
184
+ // 测试乱码字符串
185
+ assertTrue((Boolean) method.invoke(null, "???"));
186
+ assertTrue((Boolean) method.invoke(null, "??garbled??"));
187
+ assertTrue((Boolean) method.invoke(null, "\ufffd"));
188
+
189
+ // 测试null和空字符串
190
+ assertFalse((Boolean) method.invoke(null, (String) null));
191
+ assertFalse((Boolean) method.invoke(null, ""));
192
+ }
193
+
194
+ @Test
195
+ void testDetectZipFilenameCharset_UTF8() throws Exception {
196
+ // 准备UTF-8编码的ZIP文件
197
+ String fileName = "utf8_test.txt";
198
+ createZipFileWithEncoding(testZipFile.toString(), fileName, "test", StandardCharsets.UTF_8);
199
+
200
+ // 使用反射调用私有方法
201
+ java.lang.reflect.Method method = CompressUtils.class.getDeclaredMethod(
202
+ "detectZipFilenameCharset", File.class);
203
+ method.setAccessible(true);
204
+
205
+ // 执行
206
+ Charset detectedCharset = (Charset) method.invoke(null, testZipFile.toFile());
207
+
208
+ // 验证
209
+ assertNotNull(detectedCharset);
210
+ // 可能返回UTF-8或其他兼容编码
211
+ }
212
+
213
+ // 辅助方法:创建简单的ZIP文件(参考现有测试模式)
214
+ private void createTestZipFile(String zipFilePath, String fileName, String content) throws IOException {
215
+ try (OutputStream fos = Files.newOutputStream(Paths.get(zipFilePath));
216
+ BufferedOutputStream bos = new BufferedOutputStream(fos);
217
+ ZipArchiveOutputStream zos = new ZipArchiveOutputStream(bos)) {
218
+
219
+ ZipArchiveEntry entry = new ZipArchiveEntry(fileName);
220
+ byte[] contentBytes = content.getBytes(StandardCharsets.UTF_8);
221
+ entry.setSize(contentBytes.length);
222
+ zos.putArchiveEntry(entry);
223
+ zos.write(contentBytes);
224
+ zos.closeArchiveEntry();
225
+
226
+ zos.finish();
227
+ }
228
+ }
229
+
230
+ // 辅助方法:创建指定编码的ZIP文件
231
+ private void createZipFileWithEncoding(String zipFilePath, String fileName, String content, Charset encoding)
232
+ throws IOException {
233
+ try (OutputStream fos = Files.newOutputStream(Paths.get(zipFilePath));
234
+ BufferedOutputStream bos = new BufferedOutputStream(fos);
235
+ ZipArchiveOutputStream zos = new ZipArchiveOutputStream(bos)) {
236
+
237
+ zos.setEncoding(encoding.name());
238
+ ZipArchiveEntry entry = new ZipArchiveEntry(fileName);
239
+ byte[] contentBytes = content.getBytes(encoding);
240
+ entry.setSize(contentBytes.length);
241
+ zos.putArchiveEntry(entry);
242
+ zos.write(contentBytes);
243
+ zos.closeArchiveEntry();
244
+
245
+ zos.finish();
246
+ }
247
+ }
248
+
249
+ // 辅助方法:创建包含目录结构的ZIP文件
250
+ private void createTestZipWithDirectoryStructure() throws IOException {
251
+ try (OutputStream fos = Files.newOutputStream(testZipFile);
252
+ BufferedOutputStream bos = new BufferedOutputStream(fos);
253
+ ZipArchiveOutputStream zos = new ZipArchiveOutputStream(bos)) {
254
+
255
+ // 添加目录条目
256
+ ZipArchiveEntry dirEntry = new ZipArchiveEntry("folder/");
257
+ zos.putArchiveEntry(dirEntry);
258
+ zos.closeArchiveEntry();
259
+
260
+ // 添加子目录条目
261
+ ZipArchiveEntry subDirEntry = new ZipArchiveEntry("folder/subfolder/");
262
+ zos.putArchiveEntry(subDirEntry);
263
+ zos.closeArchiveEntry();
264
+
265
+ // 添加文件条目
266
+ ZipArchiveEntry fileEntry = new ZipArchiveEntry("folder/subfolder/test.txt");
267
+ byte[] content = "Nested folder content".getBytes(StandardCharsets.UTF_8);
268
+ fileEntry.setSize(content.length);
269
+ zos.putArchiveEntry(fileEntry);
270
+ zos.write(content);
271
+ zos.closeArchiveEntry();
272
+
273
+ zos.finish();
274
+ }
275
+ }
276
+
277
+ // 辅助方法:创建空的ZIP文件
278
+ private void createEmptyZipFile() throws IOException {
279
+ try (OutputStream fos = Files.newOutputStream(testZipFile);
280
+ BufferedOutputStream bos = new BufferedOutputStream(fos);
281
+ ZipArchiveOutputStream zos = new ZipArchiveOutputStream(bos)) {
282
+ // 不添加任何条目,创建空ZIP
283
+ zos.finish();
284
+ }
285
+ }
286
+ }