/** * Join the given list of buffers into a single buffer. */ private static DataBuffer joinUntilEndFrame(List<DataBuffer> dataBuffers) { if (!dataBuffers.isEmpty()) { int lastIdx = dataBuffers.size() - 1; if (isEndFrame(dataBuffers.get(lastIdx))) { dataBuffers.remove(lastIdx); } } return dataBuffers.get(0).factory().join(dataBuffers); }
/** * Join the given list of buffers into a single buffer. */ private static DataBuffer joinUntilEndFrame(List<DataBuffer> dataBuffers) { if (!dataBuffers.isEmpty()) { int lastIdx = dataBuffers.size() - 1; if (isEndFrame(dataBuffers.get(lastIdx))) { dataBuffers.remove(lastIdx); } } return dataBuffers.get(0).factory().join(dataBuffers); }
@Override public DataBuffer join(List<? extends DataBuffer> dataBuffers) { return new LeakAwareDataBuffer(this.delegate.join(dataBuffers), this); }
/** * Return a new {@code DataBuffer} composed from joining together the given * {@code dataBuffers} elements. Depending on the {@link DataBuffer} type, * the returned buffer may be a single buffer containing all data of the * provided buffers, or it may be a zero-copy, composite with references to * the given buffers. * <p>If {@code dataBuffers} produces an error or if there is a cancel * signal, then all accumulated buffers will be * {@linkplain #release(DataBuffer) released}. * <p>Note that the given data buffers do <strong>not</strong> have to be * released. They will be released as part of the returned composite. * @param dataBuffers the data buffers that are to be composed * @return a buffer that is composed from the {@code dataBuffers} argument * @since 5.0.3 */ public static Mono<DataBuffer> join(Publisher<DataBuffer> dataBuffers) { Assert.notNull(dataBuffers, "'dataBuffers' must not be null"); return Flux.from(dataBuffers) .collectList() .filter(list -> !list.isEmpty()) .map(list -> list.get(0).factory().join(list)) .doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release); }
/** * Return a new {@code DataBuffer} composed from joining together the given * {@code dataBuffers} elements. Depending on the {@link DataBuffer} type, * the returned buffer may be a single buffer containing all data of the * provided buffers, or it may be a zero-copy, composite with references to * the given buffers. * <p>If {@code dataBuffers} produces an error or if there is a cancel * signal, then all accumulated buffers will be * {@linkplain #release(DataBuffer) released}. * <p>Note that the given data buffers do <strong>not</strong> have to be * released. They will be released as part of the returned composite. * @param dataBuffers the data buffers that are to be composed * @return a buffer that is composed from the {@code dataBuffers} argument * @since 5.0.3 */ public static Mono<DataBuffer> join(Publisher<DataBuffer> dataBuffers) { Assert.notNull(dataBuffers, "'dataBuffers' must not be null"); return Flux.from(dataBuffers) .collectList() .filter(list -> !list.isEmpty()) .map(list -> list.get(0).factory().join(list)) .doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release); }
@Test public void join() { DataBuffer composite = this.bufferFactory.join(Arrays.asList(stringBuffer("a"), stringBuffer("b"), stringBuffer("c"))); assertEquals(3, composite.readableByteCount()); byte[] bytes = new byte[3]; composite.read(bytes); assertArrayEquals(new byte[] {'a','b','c'}, bytes); release(composite); }
/** * Join the given list of buffers into a single buffer. */ private static DataBuffer joinUntilEndFrame(List<DataBuffer> dataBuffers) { if (!dataBuffers.isEmpty()) { int lastIdx = dataBuffers.size() - 1; if (isEndFrame(dataBuffers.get(lastIdx))) { dataBuffers.remove(lastIdx); } } return dataBuffers.get(0).factory().join(dataBuffers); }
/** * Joins the given list of buffers into a single buffer, also removing * the (inserted) {@link #END_FRAME}. */ private static DataBuffer joinUntilEndFrame(List<DataBuffer> dataBuffers) { if (!dataBuffers.isEmpty()) { int lastIdx = dataBuffers.size() - 1; if (isEndFrame(dataBuffers.get(lastIdx))) { dataBuffers.remove(lastIdx); } } return dataBuffers.get(0).factory().join(dataBuffers); }
/** * Return a new {@code DataBuffer} composed from joining together the given * {@code dataBuffers} elements. Depending on the {@link DataBuffer} type, * the returned buffer may be a single buffer containing all data of the * provided buffers, or it may be a zero-copy, composite with references to * the given buffers. * <p>If {@code dataBuffers} produces an error or if there is a cancel * signal, then all accumulated buffers will be * {@linkplain #release(DataBuffer) released}. * <p>Note that the given data buffers do <strong>not</strong> have to be * released. They will be released as part of the returned composite. * @param dataBuffers the data buffers that are to be composed * @return a buffer that is composed from the {@code dataBuffers} argument * @since 5.0.3 */ public static Mono<DataBuffer> join(Publisher<DataBuffer> dataBuffers) { Assert.notNull(dataBuffers, "'dataBuffers' must not be null"); return Flux.from(dataBuffers) .collectList() .filter(list -> !list.isEmpty()) .map(list -> list.get(0).factory().join(list)) .doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release); }
/** * Return a new {@code DataBuffer} composed from joining together the given * {@code dataBuffers} elements. Depending on the {@link DataBuffer} type, * the returned buffer may be a single buffer containing all data of the * provided buffers, or it may be a zero-copy, composite with references to * the given buffers. * <p>If {@code dataBuffers} produces an error or if there is a cancel * signal, then all accumulated buffers will be * {@linkplain #release(DataBuffer) released}. * <p>Note that the given data buffers do <strong>not</strong> have to be * released. They will be released as part of the returned composite. * @param dataBuffers the data buffers that are to be composed * @return a buffer that is composed from the {@code dataBuffers} argument * @since 5.0.3 */ public static Mono<DataBuffer> join(Publisher<DataBuffer> dataBuffers) { Assert.notNull(dataBuffers, "'dataBuffers' must not be null"); return Flux.from(dataBuffers) .collectList() .filter(list -> !list.isEmpty()) .map(list -> list.get(0).factory().join(list)) .doOnDiscard(PooledDataBuffer.class, DataBufferUtils::release); }