Add DeterministicJarOutputStream.repack() function

I'm going to use this to make jarsigner's output deterministic.
master
Graham 5 years ago
parent b8af6c0c90
commit 33955e76c7
  1. 15
      common/src/main/java/dev/openrs2/common/io/DeterministicJarOutputStream.kt

@ -1,7 +1,10 @@
package dev.openrs2.common.io package dev.openrs2.common.io
import java.io.OutputStream import java.io.OutputStream
import java.nio.file.Files
import java.nio.file.Path
import java.nio.file.attribute.FileTime import java.nio.file.attribute.FileTime
import java.util.jar.JarInputStream
import java.util.jar.JarOutputStream import java.util.jar.JarOutputStream
import java.util.jar.Manifest import java.util.jar.Manifest
import java.util.zip.ZipEntry import java.util.zip.ZipEntry
@ -27,5 +30,17 @@ class DeterministicJarOutputStream : JarOutputStream {
DeterministicJarOutputStream(out) DeterministicJarOutputStream(out)
} }
} }
fun repack(src: Path, dest: Path) {
JarInputStream(Files.newInputStream(src)).use { `in` ->
create(Files.newOutputStream(dest), `in`.manifest).use { out ->
while (true) {
val entry = `in`.nextJarEntry ?: break
out.putNextEntry(entry)
`in`.copyTo(out)
}
}
}
}
} }
} }

Loading…
Cancel
Save