Polishing
This commit is contained in:
@@ -139,7 +139,6 @@ public abstract class DataBufferUtils {
|
||||
DataBuffer dataBuffer = dataBufferFactory.allocateBuffer(bufferSize);
|
||||
ByteBuffer byteBuffer = dataBuffer.asByteBuffer(0, bufferSize);
|
||||
|
||||
|
||||
Flux<DataBuffer> result = Flux.using(channelSupplier,
|
||||
channel -> Flux.create(sink -> {
|
||||
AsynchronousFileChannelReadCompletionHandler completionHandler =
|
||||
@@ -265,7 +264,7 @@ public abstract class DataBufferUtils {
|
||||
* @param channel the channel to write to
|
||||
* @return a flux containing the same buffers as in {@code source}, that starts the writing
|
||||
* process when subscribed to, and that publishes any writing errors and the completion signal
|
||||
* @since 5.1
|
||||
* @since 5.0.10
|
||||
*/
|
||||
public static Flux<DataBuffer> write(Publisher<DataBuffer> source, AsynchronousFileChannel channel) {
|
||||
return write(source, channel, 0);
|
||||
@@ -329,7 +328,6 @@ public abstract class DataBufferUtils {
|
||||
|
||||
return Flux.defer(() -> {
|
||||
AtomicLong countDown = new AtomicLong(maxByteCount);
|
||||
|
||||
return Flux.from(publisher)
|
||||
.map(buffer -> {
|
||||
long remainder = countDown.addAndGet(-buffer.readableByteCount());
|
||||
@@ -359,7 +357,6 @@ public abstract class DataBufferUtils {
|
||||
|
||||
return Flux.defer(() -> {
|
||||
AtomicLong countDown = new AtomicLong(maxByteCount);
|
||||
|
||||
return Flux.from(publisher)
|
||||
.skipUntil(buffer -> {
|
||||
long remainder = countDown.addAndGet(-buffer.readableByteCount());
|
||||
|
||||
@@ -26,6 +26,7 @@ import io.netty.buffer.ByteBufInputStream;
|
||||
import io.netty.buffer.ByteBufOutputStream;
|
||||
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* Implementation of the {@code DataBuffer} interface that wraps a Netty
|
||||
@@ -68,7 +69,7 @@ public class NettyDataBuffer implements PooledDataBuffer {
|
||||
|
||||
@Override
|
||||
public int indexOf(IntPredicate predicate, int fromIndex) {
|
||||
Assert.notNull(predicate, "'predicate' must not be null");
|
||||
Assert.notNull(predicate, "IntPredicate must not be null");
|
||||
if (fromIndex < 0) {
|
||||
fromIndex = 0;
|
||||
}
|
||||
@@ -81,7 +82,7 @@ public class NettyDataBuffer implements PooledDataBuffer {
|
||||
|
||||
@Override
|
||||
public int lastIndexOf(IntPredicate predicate, int fromIndex) {
|
||||
Assert.notNull(predicate, "'predicate' must not be null");
|
||||
Assert.notNull(predicate, "IntPredicate must not be null");
|
||||
if (fromIndex < 0) {
|
||||
return -1;
|
||||
}
|
||||
@@ -174,9 +175,7 @@ public class NettyDataBuffer implements PooledDataBuffer {
|
||||
|
||||
@Override
|
||||
public NettyDataBuffer write(DataBuffer... buffers) {
|
||||
Assert.notNull(buffers, "'buffers' must not be null");
|
||||
|
||||
if (buffers.length > 0) {
|
||||
if (!ObjectUtils.isEmpty(buffers)) {
|
||||
if (hasNettyDataBuffers(buffers)) {
|
||||
ByteBuf[] nativeBuffers = new ByteBuf[buffers.length];
|
||||
for (int i = 0 ; i < buffers.length; i++) {
|
||||
@@ -196,9 +195,9 @@ public class NettyDataBuffer implements PooledDataBuffer {
|
||||
return this;
|
||||
}
|
||||
|
||||
private static boolean hasNettyDataBuffers(DataBuffer[] dataBuffers) {
|
||||
for (DataBuffer dataBuffer : dataBuffers) {
|
||||
if (!(dataBuffer instanceof NettyDataBuffer)) {
|
||||
private static boolean hasNettyDataBuffers(DataBuffer[] buffers) {
|
||||
for (DataBuffer buffer : buffers) {
|
||||
if (!(buffer instanceof NettyDataBuffer)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -207,25 +206,25 @@ public class NettyDataBuffer implements PooledDataBuffer {
|
||||
|
||||
@Override
|
||||
public NettyDataBuffer write(ByteBuffer... buffers) {
|
||||
Assert.notNull(buffers, "'buffers' must not be null");
|
||||
|
||||
for (ByteBuffer buffer : buffers) {
|
||||
this.byteBuf.writeBytes(buffer);
|
||||
if (!ObjectUtils.isEmpty(buffers)) {
|
||||
for (ByteBuffer buffer : buffers) {
|
||||
this.byteBuf.writeBytes(buffer);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Writes one or more Netty {@link ByteBuf ByteBufs} to this buffer, starting at the current
|
||||
* writing position.
|
||||
* Writes one or more Netty {@link ByteBuf ByteBufs} to this buffer,
|
||||
* starting at the current writing position.
|
||||
* @param byteBufs the buffers to write into this buffer
|
||||
* @return this buffer
|
||||
*/
|
||||
public NettyDataBuffer write(ByteBuf... byteBufs) {
|
||||
Assert.notNull(byteBufs, "'byteBufs' must not be null");
|
||||
|
||||
for (ByteBuf byteBuf : byteBufs) {
|
||||
this.byteBuf.writeBytes(byteBuf);
|
||||
if (!ObjectUtils.isEmpty(byteBufs)) {
|
||||
for (ByteBuf byteBuf : byteBufs) {
|
||||
this.byteBuf.writeBytes(byteBuf);
|
||||
}
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user