private DataBuffer toDataBuffer(String value) { byte[] bytes = value.getBytes(UTF_8); return new DefaultDataBufferFactory().wrap(bytes); }
private static DataBuffer asDataBuffer(String text) { DefaultDataBuffer buffer = new DefaultDataBufferFactory().allocateBuffer(); return buffer.write(text.getBytes(StandardCharsets.UTF_8)); }
/** * Creates a new {@code LeakAwareDataBufferFactory} by wrapping a * {@link DefaultDataBufferFactory}. */ public LeakAwareDataBufferFactory() { this(new DefaultDataBufferFactory()); }
@Override public DefaultDataBuffer allocateBuffer() { return allocateBuffer(this.defaultInitialCapacity); }
/** * Terminates pending reads with empty buffers. */ void terminatePendingReads() { BiConsumer<DataBuffer, Integer> readers; while ((readers = readRequests.poll()) != null) { readers.accept(factory.wrap(new byte[0]), -1); } }
public TestServerHttpResponse() { super(new DefaultDataBufferFactory()); }
@Override public DefaultDataBuffer allocateBuffer() { return allocateBuffer(this.defaultInitialCapacity); }
private DataBuffer dataBuffer(String foo, DefaultDataBufferFactory bufferFactory) { return bufferFactory.wrap(foo.getBytes(StandardCharsets.UTF_8)); }
private DataBuffer toDataBuffer(String body) { return new DefaultDataBufferFactory().wrap(body.getBytes(UTF_8)); }
public MockServerHttpResponse() { this(new DefaultDataBufferFactory()); }
private static DataBuffer toDataBuffer(String body) { DataBuffer buffer = new DefaultDataBufferFactory().allocateBuffer(); buffer.write(body.getBytes(StandardCharsets.UTF_8)); return buffer; } }
/** * {@inheritDoc} * <p>This implementation creates a single {@link DefaultDataBuffer} * to contain the data in {@code dataBuffers}. */ @Override public DefaultDataBuffer join(List<? extends DataBuffer> dataBuffers) { Assert.notEmpty(dataBuffers, "DataBuffer List must not be empty"); int capacity = dataBuffers.stream().mapToInt(DataBuffer::readableByteCount).sum(); DefaultDataBuffer result = allocateBuffer(capacity); dataBuffers.forEach(result::write); dataBuffers.forEach(DataBufferUtils::release); return result; }
private DefaultDataBuffer wrap(String a) { return new DefaultDataBufferFactory().wrap(ByteBuffer.wrap(a.getBytes(StandardCharsets.UTF_8))); }
/** * Creates a new {@link ReactiveGridFsTemplate} using the given {@link ReactiveMongoDatabaseFactory} and * {@link MongoConverter}. * * @param dbFactory must not be {@literal null}. * @param converter must not be {@literal null}. * @param bucket */ public ReactiveGridFsTemplate(ReactiveMongoDatabaseFactory dbFactory, MongoConverter converter, @Nullable String bucket) { this(new DefaultDataBufferFactory(), dbFactory, converter, bucket); }
@Test public void testWebFilter() throws Exception { WebFilter filter = (exchange, chain) -> { DataBuffer buffer = new DefaultDataBufferFactory().allocateBuffer(); buffer.write("It works!".getBytes(StandardCharsets.UTF_8)); return exchange.getResponse().writeWith(Mono.just(buffer)); }; WebTestClient client = WebTestClient.bindToWebHandler(exchange -> Mono.empty()) .webFilter(filter) .build(); client.get().uri("/") .exchange() .expectStatus().isOk() .expectBody(String.class).isEqualTo("It works!"); }
/** * {@inheritDoc} * <p>This implementation creates a single {@link DefaultDataBuffer} * to contain the data in {@code dataBuffers}. */ @Override public DefaultDataBuffer join(List<? extends DataBuffer> dataBuffers) { Assert.notEmpty(dataBuffers, "DataBuffer List must not be empty"); int capacity = dataBuffers.stream().mapToInt(DataBuffer::readableByteCount).sum(); DefaultDataBuffer result = allocateBuffer(capacity); dataBuffers.forEach(result::write); dataBuffers.forEach(DataBufferUtils::release); return result; }
private Flux<DataBuffer> getBody(String body) { return Flux.just(new DefaultDataBufferFactory().wrap(body.getBytes(StandardCharsets.UTF_8))); } }
@Override public ClientResponse.Builder body(String body) { Assert.notNull(body, "Body must not be null"); releaseBody(); DataBufferFactory dataBufferFactory = new DefaultDataBufferFactory(); this.body = Flux.just(body). map(s -> { byte[] bytes = body.getBytes(StandardCharsets.UTF_8); return dataBufferFactory.wrap(bytes); }); return this; }
@Override public Flux<DataBuffer> getBody() { DefaultDataBuffer buffer = new DefaultDataBufferFactory().allocateBuffer(); buffer.write(this.result.getRequestBodyContent()); return Flux.fromArray(new DataBuffer[] { buffer }); }
@Override public DefaultDataBuffer allocateBuffer() { return allocateBuffer(this.defaultInitialCapacity); }