其他分享
首页 > 其他分享> > 导入zip文件解析

导入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;
}

 

标签:zipInputStream,Exception,zip,param,导入,file,解析,nextEntry,charsetName
来源: https://www.cnblogs.com/zrboke/p/16700665.html