MultiMerger implements Merger<ChunkMeta> { @Override public Completable init(ChunkMeta meta) { return ensureMerger(meta) .andThen(Completable.defer(() -> { if (meta instanceof XMLChunkMeta) { return xmlMerger.init((XMLChunkMeta)meta); } return geoJsonMerger.init((GeoJsonChunkMeta)meta); })); } MultiMerger(boolean optimistic); @Override Completable init(ChunkMeta meta); @Override Completable merge(ChunkReadStream chunk, ChunkMeta meta,
      WriteStream<Buffer> out); @Override void finish(WriteStream<Buffer> out);  }
@Test public void mixedInit(TestContext context) { String strChunk1 = "{\"type\":\"Feature\"}"; String strChunk2 = XMLHEADER + "<root><test chunk=\"2\"></test></root>"; Buffer chunk1 = Buffer.buffer(strChunk1); Buffer chunk2 = Buffer.buffer(strChunk2); GeoJsonChunkMeta cm1 = new GeoJsonChunkMeta("Feature", "features", 0, chunk1.length()); XMLChunkMeta cm2 = new XMLChunkMeta(Arrays.asList(new XMLStartElement("root")), XMLHEADER.length() + 6, chunk2.length() - 7); MultiMerger m = new MultiMerger(false); Async async = context.async(); m.init(cm1) .andThen(m.init(cm2)) .subscribe(context::fail, err -> { context.assertTrue(err instanceof IllegalStateException); async.complete(); }); }