Skip to content

Commit

Permalink
feat: 当解压临时文件异常后需要删除创建的文件#2406
Browse files Browse the repository at this point in the history
  • Loading branch information
zacYL authored Jul 29, 2024
1 parent cb89ee8 commit ae038ca
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,20 @@ object GZipUtils {
fun InputStream.unGzipInputStream(): File {
GZIPInputStream(this).use { gZIPInputStream ->
val file = File.createTempFile("rpm_", ".xmlStream")
BufferedOutputStream(FileOutputStream(file)).use { bufferedOutputStream ->
var len: Int
val buffer = ByteArray(1 * 1024 * 1024)
while (gZIPInputStream.read(buffer).also { len = it } > 0) {
bufferedOutputStream.write(buffer, 0, len)
try {
BufferedOutputStream(FileOutputStream(file)).use { bufferedOutputStream ->
var len: Int
val buffer = ByteArray(1 * 1024 * 1024)
while (gZIPInputStream.read(buffer).also { len = it } > 0) {
bufferedOutputStream.write(buffer, 0, len)
}
bufferedOutputStream.flush()
}
bufferedOutputStream.flush()
return file
} catch (e: Exception) {
file.delete()
throw e
}
return file
}
}
}

0 comments on commit ae038ca

Please sign in to comment.