java.util.zip.zipexception invalid entry compressed size

java.util.zip.zipexception invalid entry compressed size ,第1张

在gradle中使用的时候碰到了上边的错误,原本的代码如下

def tmp = File.createTempFile("temp_${System.nanoTime()}", '.zip')
        tmp.withOutputStream { os ->
            def zos = new ZipOutputStream(os)
            zin.entries().each { entry ->
                def isReplaced = entry.name == zipEntry
                println("isReplaced->"+isReplaced)
                if(isReplaced) {
                    entry.setComment(newContent)
                }
                zos.putNextEntry(entry)
                zos << (zin.getInputStream(entry).bytes)
                zos.closeEntry()
            }
            zos.close()
        }
        zin.close()

新代码如下

def tmp = File.createTempFile("temp_${System.nanoTime()}", '.zip')
        tmp.withOutputStream { os ->
            def zos = new ZipOutputStream(os)
            zin.entries().each { entry ->
                ZipEntry newZipEntry = new ZipEntry(entry.getName())
                def isReplaced = newZipEntry.name == zipEntry
                println("isReplaced->"+isReplaced)
                if(isReplaced) {
                    newZipEntry.setComment(newContent)
                }
                zos.putNextEntry(newZipEntry)
                zos << (zin.getInputStream(newZipEntry).bytes)
                zos.closeEntry()
            }
            zos.close()
        }
        zin.close()

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/905973.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-15
下一篇 2022-05-15

发表评论

登录后才能评论

评论列表(0条)

保存