diff --git a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt index 2a604339..ba3a61c4 100644 --- a/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt +++ b/src/test/kotlin/com/beust/kobalt/VerifyKobaltZipTest.kt @@ -117,32 +117,7 @@ class VerifyKobaltZipTest : KobaltTest() { } } - private fun toSequence(ins: InputStream) = Sequence { JarInputStreamIterator(JarInputStream(ins)) } -} - -/** - * I don't want to hold the whole content of the jar file in memory to run tests on its content, - * so this iterator allows me to create a sequence out of it, so each entry in the jar file can - * be verified lazily - */ -class JarInputStreamIterator(val ins: JarInputStream) : Iterator { - var next: JarEntry? = null - - override fun next(): JarEntry { - if (next != null) { - next?.let { - val result = it - next = null - return result - } - } else { - return ins.nextJarEntry - } - throw IllegalArgumentException("Should never happen") - } - - override fun hasNext(): Boolean { - if (next == null) next = ins.nextJarEntry - return next != null - } + fun JarInputStream.asSequence() = generateSequence { nextJarEntry } + + private fun toSequence(ins: InputStream): Sequence = JarInputStream(ins).asSequence() }