Skip to content

Commit dd79813

Browse files
committed
fix(abg): fix file handle leak in jar creation
1 parent d909c4e commit dd79813

File tree

1 file changed

+4
-26
lines changed
  • maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding

1 file changed

+4
-26
lines changed

maven-binding-builder/src/main/kotlin/io/github/typesafegithub/workflows/mavenbinding/ZipUtils.kt

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package io.github.typesafegithub.workflows.mavenbinding
22

3-
import com.intellij.util.io.PagedFileStorage
43
import java.io.BufferedInputStream
54
import java.io.File
65
import java.io.FileInputStream
@@ -30,7 +29,6 @@ internal fun OutputStream.createZipFile(contents: Path) =
3029
zipFile(file.toFile(), zipOutputStream)
3130
}
3231
}
33-
zipOutputStream.flush()
3432
}
3533

3634
/**
@@ -61,17 +59,8 @@ private fun zipDirectory(
6159
lastAccessTime = FileTime.fromMillis(0)
6260
}
6361
zos.putNextEntry(zipEntry)
64-
val bis =
65-
BufferedInputStream(
66-
FileInputStream(file),
67-
)
68-
var bytesRead: Long = 0
69-
val bytesIn = ByteArray(PagedFileStorage.BUFFER_SIZE)
70-
var read: Int
71-
while ((bis.read(bytesIn).also { read = it }) != -1) {
72-
zos.write(bytesIn, 0, read)
73-
bytesRead += read.toLong()
74-
}
62+
BufferedInputStream(FileInputStream(file))
63+
.use { it.copyTo(zos) }
7564
zos.closeEntry()
7665
}
7766
}
@@ -97,18 +86,7 @@ private fun zipFile(
9786
lastAccessTime = FileTime.fromMillis(0)
9887
}
9988
zos.putNextEntry(zipEntry)
100-
val bis =
101-
BufferedInputStream(
102-
FileInputStream(
103-
file,
104-
),
105-
)
106-
var bytesRead: Long = 0
107-
val bytesIn = ByteArray(PagedFileStorage.BUFFER_SIZE)
108-
var read: Int
109-
while ((bis.read(bytesIn).also { read = it }) != -1) {
110-
zos.write(bytesIn, 0, read)
111-
bytesRead += read.toLong()
112-
}
89+
BufferedInputStream(FileInputStream(file))
90+
.use { it.copyTo(zos) }
11391
zos.closeEntry()
11492
}

0 commit comments

Comments
 (0)