Scala 2.10.2 standard library scala.io.Source
(you want object Source
, not abstract class Source
) offers a number of from*
methods, including fromInputStream
and fromURL
.
Scala 2.9.X is, if I recall, similar if not the same.
Question
Originally I was trying to use Java APIs for this, but now I am going to see if I can use Scala to parse XML documents coming through an XML stream. The following is a basic setup of XMLEventReader
:
val reader = new xml.pull.XMLEventReader(IOSource)
while (reader.hasNext) System.out.println(reader.next)
The problem is IOSource
must be a form of scala.io.Source
and I'm only seeing local file methods for such parsing. What native Scala APIs can I use to feed XML coming from streaming HTTP to the event reader?
Thanks!
Looks like a Java API is going to be necessary. So instead, is it possible to convert a Java InputStream
into a Scala io.Source
?
Solution
Scala 2.10.2 standard library scala.io.Source
(you want object Source
, not abstract class Source
) offers a number of from*
methods, including fromInputStream
and fromURL
.
Scala 2.9.X is, if I recall, similar if not the same.