Skip to content

Instantly share code, notes, and snippets.

@fancellu
Last active August 29, 2015 14:00
Show Gist options
  • Save fancellu/780d7c3dab1a8309f561 to your computer and use it in GitHub Desktop.
Save fancellu/780d7c3dab1a8309f561 to your computer and use it in GitHub Desktop.
import java.io.File
object Stream extends App {
import scala.xml.pull._
import scala.io.Source
// won't exit. Both main and XMLEventReader thread stuck on ProducerConsumerIterator.produce
// How am I supposed to end reader early?
// Using Scala 2.11 and scala-xml 1.0.1
// Seems to do same for Scala 2.10.2
val src = Source.fromFile(new File("e:/downloads/medsamp2014.xml"))
// if I download http://dumps.wikimedia.org/enwiki/20140402/enwiki-20140402-abstract.xml
// then ref that, does not exit after er.stop, even without Thread.sleep.
// Seems to run to end of the 4gb file!
val ti=System.currentTimeMillis()
val er = new XMLEventReader(src)
er.take(100).foreach {println}
// same this way too
// var count=0;
// while (er.hasNext&&count<10){
// val ev=er.next()
// count+=1
// println(ev)
// }
println("Time ="+(System.currentTimeMillis()-ti))
// take out sleep, it works fine.
Thread.sleep(500)
er.stop()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment