Using the ktor client, how do I save an xml file f...
# ktor
f
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
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
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
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
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
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
223 Views