Make StringDecoder use DataBufferUtils.split

* Added DataBufferUtils.split variant that takes multiple delimiters
  as argument (instead of 1).
* Use this new split() variant from within StringDecoder, replacing
  its inefficient algorithm with the Knuth-Morris-Pratt algorithm.
This commit is contained in:
Arjen Poutsma
2019-05-15 16:07:05 +02:00
parent b1912f6acc
commit a30a134c23
3 changed files with 286 additions and 133 deletions

View File

@@ -820,6 +820,25 @@ public class DataBufferUtilsTests extends AbstractDataBufferAllocatingTestCase {
.verifyComplete();
}
@Test
public void splitMultipleDelimiters() {
Mono<DataBuffer> source =
deferStringBuffer("foo␤bar␍␤baz␤");
byte[][] delimiters = new byte[][]{
"".getBytes(StandardCharsets.UTF_8),
"␍␤".getBytes(StandardCharsets.UTF_8)
};
Flux<DataBuffer> result = DataBufferUtils.split(source, delimiters, false);
StepVerifier.create(result)
.consumeNextWith(stringConsumer("foo␤"))
.consumeNextWith(stringConsumer("bar␍␤"))
.consumeNextWith(stringConsumer("baz␤"))
.verifyComplete();
}
@Test
public void splitErrors() {
Flux<DataBuffer> source = Flux.concat(