Created
April 4, 2012 15:13
-
-
Save mnylen/2302484 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
val zip = new ZipStreamHelper(new ZipInputStream(...)) | |
zip.rewindTo("hello.xml") { in => | |
val parser = STaxParser() | |
val root = parser.fromInputStream(in) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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