Added measureTimeMillis blocks and comments.
This commit is contained in:
parent
29161d627d
commit
03bc4c3e9f
1 changed files with 60 additions and 47 deletions
|
@ -3,6 +3,7 @@ package com.example
|
||||||
import org.apache.commons.compress.archivers.zip.*
|
import org.apache.commons.compress.archivers.zip.*
|
||||||
import java.io.File
|
import java.io.File
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
import kotlin.system.measureTimeMillis
|
||||||
|
|
||||||
internal var allFilesPredicate: ZipArchiveEntryPredicate = ZipArchiveEntryPredicate { true }
|
internal var allFilesPredicate: ZipArchiveEntryPredicate = ZipArchiveEntryPredicate { true }
|
||||||
|
|
||||||
|
@ -15,20 +16,25 @@ fun main(args: Array<String>) {
|
||||||
rezip3(kobalt, src, zip)
|
rezip3(kobalt, src, zip)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Straight raw copy, not very flexible
|
||||||
fun rezip(jarIn: File, zipOut: File) {
|
fun rezip(jarIn: File, zipOut: File) {
|
||||||
val s = System.currentTimeMillis()
|
val time = measureTimeMillis {
|
||||||
val zos = ZipArchiveOutputStream(zipOut)
|
val zos = ZipArchiveOutputStream(zipOut)
|
||||||
zos.encoding = "UTF-8"
|
zos.encoding = "UTF-8"
|
||||||
val zip = ZipFile(jarIn)
|
val zip = ZipFile(jarIn)
|
||||||
|
|
||||||
zip.copyRawEntries(zos, allFilesPredicate)
|
zip.copyRawEntries(zos, allFilesPredicate)
|
||||||
|
|
||||||
zos.close()
|
zos.close()
|
||||||
zip.close()
|
zip.close()
|
||||||
|
|
||||||
println("Rezip Time: " + (System.currentTimeMillis() - s) + "ms")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println("Rezip Time: $time ms")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Raw copy: jar -> zip
|
||||||
fun rezip2(jarIn: File, zipOut: File) {
|
fun rezip2(jarIn: File, zipOut: File) {
|
||||||
val s = System.currentTimeMillis()
|
val time = measureTimeMillis {
|
||||||
val zos = ZipArchiveOutputStream(zipOut)
|
val zos = ZipArchiveOutputStream(zipOut)
|
||||||
zos.encoding = "UTF-8"
|
zos.encoding = "UTF-8"
|
||||||
val zip = ZipFile(jarIn)
|
val zip = ZipFile(jarIn)
|
||||||
|
@ -40,26 +46,32 @@ fun rezip2(jarIn: File, zipOut: File) {
|
||||||
zos.close()
|
zos.close()
|
||||||
|
|
||||||
zip.close()
|
zip.close()
|
||||||
|
|
||||||
println("Rezip2 Time: " + (System.currentTimeMillis() - s) + "ms")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println("Rezip2 Time: $time ms")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Raw copy: jar x 2 -> zip
|
||||||
fun rezip3(jarIn: File, srcJar: File, zipOut: File) {
|
fun rezip3(jarIn: File, srcJar: File, zipOut: File) {
|
||||||
val s = System.currentTimeMillis()
|
val time = measureTimeMillis {
|
||||||
val zos = ZipArchiveOutputStream(zipOut)
|
val zos = ZipArchiveOutputStream(zipOut)
|
||||||
zos.encoding = "UTF-8"
|
zos.encoding = "UTF-8"
|
||||||
val jar = ZipFile(jarIn)
|
val jar = ZipFile(jarIn)
|
||||||
|
|
||||||
|
// get the jar entries
|
||||||
val jarEntries = jar.entries
|
val jarEntries = jar.entries
|
||||||
|
|
||||||
|
// copy the entries
|
||||||
for (entry in jar.entries) {
|
for (entry in jar.entries) {
|
||||||
zos.addRawArchiveEntry(entry, jar.getRawInputStream(entry))
|
zos.addRawArchiveEntry(entry, jar.getRawInputStream(entry))
|
||||||
}
|
}
|
||||||
|
|
||||||
jar.close()
|
jar.close()
|
||||||
|
|
||||||
|
// get the src jar entries
|
||||||
val src = ZipFile(srcJar)
|
val src = ZipFile(srcJar)
|
||||||
|
|
||||||
|
// copy the entries, no dups
|
||||||
for (entry in src.entries) {
|
for (entry in src.entries) {
|
||||||
if (!entryExists(jarEntries, entry)) {
|
if (!entryExists(jarEntries, entry)) {
|
||||||
zos.addRawArchiveEntry(entry, src.getRawInputStream(entry))
|
zos.addRawArchiveEntry(entry, src.getRawInputStream(entry))
|
||||||
|
@ -67,12 +79,13 @@ fun rezip3(jarIn: File, srcJar: File, zipOut: File) {
|
||||||
}
|
}
|
||||||
|
|
||||||
src.close()
|
src.close()
|
||||||
|
|
||||||
zos.close()
|
zos.close()
|
||||||
|
|
||||||
println("Rezip3 Time: " + (System.currentTimeMillis() - s) + "ms")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
println("Rezip3 Time: $time ms")
|
||||||
|
}
|
||||||
|
|
||||||
|
// Look for duplicate entries
|
||||||
fun entryExists(jarEntries: Enumeration<ZipArchiveEntry>, entry: ZipArchiveEntry): Boolean {
|
fun entryExists(jarEntries: Enumeration<ZipArchiveEntry>, entry: ZipArchiveEntry): Boolean {
|
||||||
for (e in jarEntries) {
|
for (e in jarEntries) {
|
||||||
if (e.name == entry.name) {
|
if (e.name == entry.name) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue