Created
September 30, 2015 15:55
-
-
Save jbrisbin/f8e03aecd48c67275ea3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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