Skip to content

Instantly share code, notes, and snippets.

@jbrisbin
Created September 30, 2015 15:55
Show Gist options
  • Save jbrisbin/f8e03aecd48c67275ea3 to your computer and use it in GitHub Desktop.
Save jbrisbin/f8e03aecd48c67275ea3 to your computer and use it in GitHub Desktop.
package reactor.groovy.ext
import groovy.transform.CompileStatic
import groovy.util.slurpersupport.GPathResult
import org.reactivestreams.Publisher
import reactor.io.buffer.Buffer
import reactor.rx.Stream
import reactor.rx.Streams
@CompileStatic
class XmlSlurperStaticExtensions {
static Stream<GPathResult> parse(XmlSlurper selfType, Publisher<Buffer> p) {
def x = new XmlSlurper()
def b = new Buffer()
Streams.createWith { req, sub ->
Streams.wrap(p).
observeComplete {
b.flip()
sub.onNext(x.parse(new ByteArrayInputStream(b.asBytes())))
}.
consume {
b.append(it)
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment