Skip to content

Commit 325bd88

Browse files
authored
fix(abg): fix file handle leak in jar creation (#1616)
1 parent 2b60e3a commit 325bd88

File tree

1 file changed

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

1 file changed

+4
-27
lines changed

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

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ internal fun OutputStream.createZipFile(contents: Path) =
2929
zipFile(file.toFile(), zipOutputStream)
3030
}
3131
}
32-
zipOutputStream.flush()
3332
}
3433

3534
/**
@@ -60,17 +59,8 @@ private fun zipDirectory(
6059
lastAccessTime = FileTime.fromMillis(0)
6160
}
6261
zos.putNextEntry(zipEntry)
63-
val bis =
64-
BufferedInputStream(
65-
FileInputStream(file),
66-
)
67-
var bytesRead: Long = 0
68-
val bytesIn = ByteArray(BUFFER_SIZE)
69-
var read: Int
70-
while ((bis.read(bytesIn).also { read = it }) != -1) {
71-
zos.write(bytesIn, 0, read)
72-
bytesRead += read.toLong()
73-
}
62+
BufferedInputStream(FileInputStream(file))
63+
.use { it.copyTo(zos) }
7464
zos.closeEntry()
7565
}
7666
}
@@ -96,20 +86,7 @@ private fun zipFile(
9686
lastAccessTime = FileTime.fromMillis(0)
9787
}
9888
zos.putNextEntry(zipEntry)
99-
val bis =
100-
BufferedInputStream(
101-
FileInputStream(
102-
file,
103-
),
104-
)
105-
var bytesRead: Long = 0
106-
val bytesIn = ByteArray(BUFFER_SIZE)
107-
var read: Int
108-
while ((bis.read(bytesIn).also { read = it }) != -1) {
109-
zos.write(bytesIn, 0, read)
110-
bytesRead += read.toLong()
111-
}
89+
BufferedInputStream(FileInputStream(file))
90+
.use { it.copyTo(zos) }
11291
zos.closeEntry()
11392
}
114-
115-
private const val BUFFER_SIZE = 8192

0 commit comments

Comments
 (0)