https://kotlinlang.org logo
#ktor
Title
# ktor
f

frellan

12/08/2018, 10:49 PM
Using the ktor client, how do I save an xml file from a http call as a
File
so I can process it with a DOM parser? I guess I readBytes and then do something but I don’t really know, surely download an xml file must be something quite standard.
g

gildor

12/09/2018, 5:02 AM
So your primary task process response using DOM parser or download file? Because it's not necessary to save response to file just to parse it, everything depends on your use case and task
f

frellan

12/09/2018, 9:46 AM
Yeah, I can parse it as a String too but that seams real cumbersome to do. Java parers really wants a file. Maybe it would be nice to save the file to disk to use SAX and not having to load everything into memory (it is really big sitemaps). How do one save a file?
readBytes
?
g

gildor

12/09/2018, 10:25 AM
SAX can parse input without problem from string or input stream
So you don't need file for that, you can just pass inputStream to SAX (as I remember you can convert response channel to input stream with openStream() function
f

frellan

12/09/2018, 10:31 AM
Yeah thats what Im after, convert the http response stream to an
InputStream
. I can’t find any examples, I feel like the dog who has no idea what he is doing 🙂 but thanks, I know more of a direction now!
g

gildor

12/09/2018, 11:06 AM
BTW this is official example how to save response to file non-blockinh (inputStream is blocking API) https://ktor.io/samples/other/client-tools.html
👍 1
149 Views