/**
* 导入压缩文件
*
* @param file
* @param charsetName
* @param consumer
*/
public static void importZipFile(MultipartFile file, String charsetName, ThrowExceptionBiConsumer<ZipInputStream, ZipEntry> consumer)
{
try (ZipInputStream zipInputStream = new ZipInputStream(file.getInputStream(), Charset.forName(charsetName)))
{
while (true)
{
ZipEntry nextEntry = zipInputStream.getNextEntry();
if (nextEntry == null)
{
break;
}
consumer.accept(zipInputStream, nextEntry);
}
}
catch (Exception e)
{
log.error(e.getMessage(), e);
throw new BaseException(e.getMessage(), e);
}
}
/**
* 抛出异常函数接口
*
* @author
* @date 2021/5/13
*/
@FunctionalInterface
public interface ThrowExceptionBiConsumer<T, U>
{
/**
* 对给定参数执行此操作
*
* @param t
* @param u
* @throws Exception
*/
void accept(T t, U u) throws Exception;
}