package com.xh.generator.domain.test;
import cn.hutool.core.io.IoUtil;
import com.xh.generator.domain.GeneratorDomain;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringRunner;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.Map;
import java.util.zip.ZipEntry;
import java.util.zip.ZipOutputStream;
@Slf4j
@RunWith(SpringRunner.class)
@SpringBootTest
public class GeneratorDomainTest {
@Autowired
private GeneratorDomain mysqlDomain;
@Test
public void outputString() {
try (ZipOutputStream zip = new ZipOutputStream(new FileOutputStream("D:/demo.zip"))) {
Map<String, String> map = mysqlDomain.outputString("res_reminder");
map.forEach((k, v) -> {
try {
zip.putNextEntry(new ZipEntry(k));
IoUtil.writeUtf8(zip, false, v);
zip.flush();
zip.closeEntry();
} catch (IOException e) {
e.printStackTrace();
}
});
} catch (FileNotFoundException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}