解决循环遍历和异步执行的问题
parent
facd67a69a
commit
885cbda543
@ -0,0 +1,56 @@
|
|||||||
|
package me.zhengjie.modules.uploadnew.util;
|
||||||
|
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
import me.zhengjie.modules.uploadnew.service.dto.WavDTO;
|
||||||
|
import org.apache.commons.lang3.StringUtils;
|
||||||
|
import org.springframework.stereotype.Component;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.BufferedInputStream;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.nio.charset.Charset;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.zip.ZipEntry;
|
||||||
|
import java.util.zip.ZipInputStream;
|
||||||
|
|
||||||
|
import static me.zhengjie.modules.constant.FileConstant.SPLIT_FILE_SYMBOL;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author wjt
|
||||||
|
* @date 2021/8/10
|
||||||
|
*/
|
||||||
|
@Component
|
||||||
|
@Slf4j
|
||||||
|
public class ZipUtils {
|
||||||
|
|
||||||
|
public List<WavDTO> zipUtil(MultipartFile file) {
|
||||||
|
List<WavDTO> wavs = new ArrayList<>();
|
||||||
|
String zipFileName = null;
|
||||||
|
try {
|
||||||
|
ZipInputStream zipInputStream = new ZipInputStream(file.getInputStream(), Charset.forName("GBK"));
|
||||||
|
BufferedInputStream bs = new BufferedInputStream(zipInputStream);
|
||||||
|
ZipEntry zipEntry;
|
||||||
|
byte[] bytes = null;
|
||||||
|
while ((zipEntry = zipInputStream.getNextEntry()) != null) {
|
||||||
|
if (!zipEntry.isDirectory()) {
|
||||||
|
if (zipEntry.getSize() > 0) {
|
||||||
|
WavDTO wavDTO = new WavDTO();
|
||||||
|
zipFileName = zipEntry.getName();
|
||||||
|
wavDTO.setName(zipFileName.substring(zipFileName.lastIndexOf("/") + 1, zipFileName.lastIndexOf(SPLIT_FILE_SYMBOL)));
|
||||||
|
wavDTO.setSubFixFile(StringUtils.substringAfterLast(zipFileName, SPLIT_FILE_SYMBOL));
|
||||||
|
bytes = new byte[(int) zipEntry.getSize()];
|
||||||
|
bs.read(bytes, 0, (int) zipEntry.getSize());
|
||||||
|
InputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
|
||||||
|
wavDTO.setLine(byteArrayInputStream);
|
||||||
|
wavs.add(wavDTO);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("读取部署包文件内容失败,请确认部署包格式正确: {} ", zipFileName, e);
|
||||||
|
}
|
||||||
|
return wavs;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue