提交 133b8b0b 编写于 作者: R Rossen Stoyanchev

Polish

上级 dc8f6f71
......@@ -179,15 +179,18 @@ public class NettyDataBuffer implements PooledDataBuffer {
if (buffers.length > 0) {
if (hasNettyDataBuffers(buffers)) {
ByteBuf[] nativeBuffers = Arrays.stream(buffers)
.map(b -> ((NettyDataBuffer) b).getNativeBuffer())
.toArray(ByteBuf[]::new);
ByteBuf[] nativeBuffers = new ByteBuf[buffers.length];
for (int i = 0 ; i < buffers.length; i++) {
nativeBuffers[i] = ((NettyDataBuffer) buffers[i]).getNativeBuffer();
}
write(nativeBuffers);
}
else {
ByteBuffer[] byteBuffers =
Arrays.stream(buffers).map(DataBuffer::asByteBuffer)
.toArray(ByteBuffer[]::new);
ByteBuffer[] byteBuffers = new ByteBuffer[buffers.length];
for (int i = 0 ; i < buffers.length; i++) {
byteBuffers[i] = buffers[i].asByteBuffer();
}
write(byteBuffers);
}
}
......
......@@ -82,6 +82,15 @@ public class NettyDataBufferFactory implements DataBufferFactory {
return new NettyDataBuffer(byteBuf, this);
}
/**
* Wrap the given Netty {@link ByteBuf} in a {@code NettyDataBuffer}.
* @param byteBuf the Netty byte buffer to wrap
* @return the wrapped buffer
*/
public NettyDataBuffer wrap(ByteBuf byteBuf) {
return new NettyDataBuffer(byteBuf, this);
}
/**
* {@inheritDoc}
* <p>This implementation uses Netty's {@link CompositeByteBuf}.
......@@ -97,15 +106,6 @@ public class NettyDataBufferFactory implements DataBufferFactory {
return new NettyDataBuffer(composite, this);
}
/**
* Wrap the given Netty {@link ByteBuf} in a {@code NettyDataBuffer}.
* @param byteBuf the Netty byte buffer to wrap
* @return the wrapped buffer
*/
public NettyDataBuffer wrap(ByteBuf byteBuf) {
return new NettyDataBuffer(byteBuf, this);
}
/**
* Return the given Netty {@link DataBuffer} as a {@link ByteBuf}. Returns the
* {@linkplain NettyDataBuffer#getNativeBuffer() native buffer} if {@code buffer} is
......
......@@ -127,13 +127,13 @@ public abstract class AbstractMessageReaderArgumentResolver extends HandlerMetho
/**
* Read the body from a method argument with {@link HttpMessageReader}.
* @param bodyParam the {@link MethodParameter} to read
* @param actualParam the actual {@link MethodParameter} to read; could be different
* from {@code bodyParameter} when processing {@code HttpEntity} for example
* @param bodyParam represents the element type for the body
* @param actualParam the actual method argument type; possibly different
* from {@code bodyParam}, e.g. for an {@code HttpEntity} argument
* @param isBodyRequired true if the body is required
* @param bindingContext the binding context to use
* @param exchange the current exchange
* @return the body
* @return a Mono with the value to use for the method argument
* @since 5.0.2
*/
protected Mono<Object> readBody(MethodParameter bodyParam, @Nullable MethodParameter actualParam,
......@@ -151,6 +151,7 @@ public abstract class AbstractMessageReaderArgumentResolver extends HandlerMetho
MediaType contentType = request.getHeaders().getContentType();
MediaType mediaType = (contentType != null ? contentType : MediaType.APPLICATION_OCTET_STREAM);
Object[] hints = extractValidationHints(bodyParam);
if (logger.isDebugEnabled()) {
logger.debug(exchange.getLogPrefix() + (contentType != null ?
......@@ -170,7 +171,6 @@ public abstract class AbstractMessageReaderArgumentResolver extends HandlerMetho
if (isBodyRequired) {
flux = flux.switchIfEmpty(Flux.error(() -> handleMissingBody(bodyParam)));
}
Object[] hints = extractValidationHints(bodyParam);
if (hints != null) {
flux = flux.doOnNext(target ->
validate(target, hints, bodyParam, bindingContext, exchange));
......@@ -187,7 +187,6 @@ public abstract class AbstractMessageReaderArgumentResolver extends HandlerMetho
if (isBodyRequired) {
mono = mono.switchIfEmpty(Mono.error(() -> handleMissingBody(bodyParam)));
}
Object[] hints = extractValidationHints(bodyParam);
if (hints != null) {
mono = mono.doOnNext(target ->
validate(target, hints, bodyParam, bindingContext, exchange));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册