导入zip文件解析

    /**
     * 导入压缩文件
     *
     * @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;
}

 

posted @ 2022-09-16 17:20  这很周锐  阅读(52)  评论(0编辑  收藏  举报