Skip to content

Instantly share code, notes, and snippets.

@mnylen
Created April 4, 2012 15:13
Show Gist options
  • Save mnylen/2302484 to your computer and use it in GitHub Desktop.
Save mnylen/2302484 to your computer and use it in GitHub Desktop.
val zip = new ZipStreamHelper(new ZipInputStream(...))
zip.rewindTo("hello.xml") { in =>
val parser = STaxParser()
val root = parser.fromInputStream(in)
}
import java.util.zip.{ZipEntry, ZipInputStream}
import java.io.InputStream
class ZipStreamHelper(zin: ZipInputStream) {
def rewindTo(name: String)(handler: InputStream => Unit) {
def findEntry(): Option[ZipEntry] = {
val entry = zin.getNextEntry
if (entry == null)
None
else if (entry.getName == name)
Some(entry)
else
findEntry()
}
findEntry() match {
case Some(_) => handler(zin)
case None =>
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment