package com.xjrsoft.module.personnel.controller;

import com.xjrsoft.XjrSoftApplication;
import com.xjrsoft.common.utils.UploadUtil;
import org.junit.jupiter.api.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.mock.web.MockMultipartFile;
import org.springframework.test.context.junit4.SpringRunner;
import org.springframework.web.multipart.MultipartFile;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
import java.util.zip.ZipEntry;
import java.util.zip.ZipInputStream;

import static org.junit.jupiter.api.Assertions.*;

/**
 * @author dzx
 * @date 2024/5/22
 */
@RunWith(SpringRunner.class)
@SpringBootTest(classes = XjrSoftApplication.class)
class StundentFaceProcessControllerTest {

    @Test
    void test() throws Exception {
        String filePath = "C:\\Users\\14263\\Downloads\\face.rar";
        File file = new File(filePath);
        FileInputStream input = new FileInputStream(file);
        MultipartFile multipartFile = new MockMultipartFile("file",
                file.getName(), "text/plain", input);
        String uploadedFile = UploadUtil.uploadFile(multipartFile);

        InputStream download = UploadUtil.download(uploadedFile);

        readZipEntries(download);
    }

    public static void readZipEntries(InputStream inputStream) throws IOException {
        try (ZipInputStream zipInputStream = new ZipInputStream(inputStream)) {
            ZipEntry zipEntry;
            while ((zipEntry = zipInputStream.getNextEntry()) != null) {
                // 处理每个zip条目
                System.out.println("Zip Entry: " + zipEntry.getName());
                zipInputStream.closeEntry();
            }
        }
    }
}