Polish
This commit is contained in:
parent
dc8f6f7177
commit
133b8b0b5a
|
|
@ -179,15 +179,18 @@ public class NettyDataBuffer implements PooledDataBuffer {
|
||||||
|
|
||||||
if (buffers.length > 0) {
|
if (buffers.length > 0) {
|
||||||
if (hasNettyDataBuffers(buffers)) {
|
if (hasNettyDataBuffers(buffers)) {
|
||||||
ByteBuf[] nativeBuffers = Arrays.stream(buffers)
|
ByteBuf[] nativeBuffers = new ByteBuf[buffers.length];
|
||||||
.map(b -> ((NettyDataBuffer) b).getNativeBuffer())
|
for (int i = 0 ; i < buffers.length; i++) {
|
||||||
.toArray(ByteBuf[]::new);
|
nativeBuffers[i] = ((NettyDataBuffer) buffers[i]).getNativeBuffer();
|
||||||
|
}
|
||||||
write(nativeBuffers);
|
write(nativeBuffers);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
ByteBuffer[] byteBuffers =
|
ByteBuffer[] byteBuffers = new ByteBuffer[buffers.length];
|
||||||
Arrays.stream(buffers).map(DataBuffer::asByteBuffer)
|
for (int i = 0 ; i < buffers.length; i++) {
|
||||||
.toArray(ByteBuffer[]::new);
|
byteBuffers[i] = buffers[i].asByteBuffer();
|
||||||
|
|
||||||
|
}
|
||||||
write(byteBuffers);
|
write(byteBuffers);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,15 @@ public class NettyDataBufferFactory implements DataBufferFactory {
|
||||||
return new NettyDataBuffer(byteBuf, this);
|
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}
|
* {@inheritDoc}
|
||||||
* <p>This implementation uses Netty's {@link CompositeByteBuf}.
|
* <p>This implementation uses Netty's {@link CompositeByteBuf}.
|
||||||
|
|
@ -97,15 +106,6 @@ public class NettyDataBufferFactory implements DataBufferFactory {
|
||||||
return new NettyDataBuffer(composite, this);
|
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
|
* Return the given Netty {@link DataBuffer} as a {@link ByteBuf}. Returns the
|
||||||
* {@linkplain NettyDataBuffer#getNativeBuffer() native buffer} if {@code buffer} is
|
* {@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}.
|
* Read the body from a method argument with {@link HttpMessageReader}.
|
||||||
* @param bodyParam the {@link MethodParameter} to read
|
* @param bodyParam represents the element type for the body
|
||||||
* @param actualParam the actual {@link MethodParameter} to read; could be different
|
* @param actualParam the actual method argument type; possibly different
|
||||||
* from {@code bodyParameter} when processing {@code HttpEntity} for example
|
* from {@code bodyParam}, e.g. for an {@code HttpEntity} argument
|
||||||
* @param isBodyRequired true if the body is required
|
* @param isBodyRequired true if the body is required
|
||||||
* @param bindingContext the binding context to use
|
* @param bindingContext the binding context to use
|
||||||
* @param exchange the current exchange
|
* @param exchange the current exchange
|
||||||
* @return the body
|
* @return a Mono with the value to use for the method argument
|
||||||
* @since 5.0.2
|
* @since 5.0.2
|
||||||
*/
|
*/
|
||||||
protected Mono<Object> readBody(MethodParameter bodyParam, @Nullable MethodParameter actualParam,
|
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 contentType = request.getHeaders().getContentType();
|
||||||
MediaType mediaType = (contentType != null ? contentType : MediaType.APPLICATION_OCTET_STREAM);
|
MediaType mediaType = (contentType != null ? contentType : MediaType.APPLICATION_OCTET_STREAM);
|
||||||
|
Object[] hints = extractValidationHints(bodyParam);
|
||||||
|
|
||||||
if (logger.isDebugEnabled()) {
|
if (logger.isDebugEnabled()) {
|
||||||
logger.debug(exchange.getLogPrefix() + (contentType != null ?
|
logger.debug(exchange.getLogPrefix() + (contentType != null ?
|
||||||
|
|
@ -170,7 +171,6 @@ public abstract class AbstractMessageReaderArgumentResolver extends HandlerMetho
|
||||||
if (isBodyRequired) {
|
if (isBodyRequired) {
|
||||||
flux = flux.switchIfEmpty(Flux.error(() -> handleMissingBody(bodyParam)));
|
flux = flux.switchIfEmpty(Flux.error(() -> handleMissingBody(bodyParam)));
|
||||||
}
|
}
|
||||||
Object[] hints = extractValidationHints(bodyParam);
|
|
||||||
if (hints != null) {
|
if (hints != null) {
|
||||||
flux = flux.doOnNext(target ->
|
flux = flux.doOnNext(target ->
|
||||||
validate(target, hints, bodyParam, bindingContext, exchange));
|
validate(target, hints, bodyParam, bindingContext, exchange));
|
||||||
|
|
@ -187,7 +187,6 @@ public abstract class AbstractMessageReaderArgumentResolver extends HandlerMetho
|
||||||
if (isBodyRequired) {
|
if (isBodyRequired) {
|
||||||
mono = mono.switchIfEmpty(Mono.error(() -> handleMissingBody(bodyParam)));
|
mono = mono.switchIfEmpty(Mono.error(() -> handleMissingBody(bodyParam)));
|
||||||
}
|
}
|
||||||
Object[] hints = extractValidationHints(bodyParam);
|
|
||||||
if (hints != null) {
|
if (hints != null) {
|
||||||
mono = mono.doOnNext(target ->
|
mono = mono.doOnNext(target ->
|
||||||
validate(target, hints, bodyParam, bindingContext, exchange));
|
validate(target, hints, bodyParam, bindingContext, exchange));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue