类 DataBufferUtils
DataBuffers.- 从以下版本开始:
- 4.0
- 作者:
- Arjen Poutsma, Brian Clozel, Harry Yang
-
嵌套类概要
嵌套类修饰符和类型类说明private static classBase class for aDataBufferUtils.NestedMatcher.private static classMatcher that supports searching for multiple delimiters.private static classImplementation ofDataBufferUtils.Matcherthat uses the Knuth-Morris-Pratt algorithm.static interfaceContract to find delimiter(s) against one or more data buffers that can be passed one at a time to theDataBufferUtils.Matcher.match(DataBuffer)method.private static interfaceMatcher that can be nested withinDataBufferUtils.CompositeMatcherwhere multiple matchers advance together using the same index, one byte at a time.private static classprivate static classprivate static classMatcher for a single byte delimiter.private static classMatcher with a 2 byte delimiter that does not benefit from a Knuth-Morris-Pratt suffix-prefix table.private static classprivate static class -
字段概要
字段修饰符和类型字段说明private static final intprivate static final Loggerprivate static final Consumer<DataBuffer> -
构造器概要
构造器 -
方法概要
修饰符和类型方法说明private static Set<OpenOption>checkWriteOptions(OpenOption[] options) (专用程序包) static voidcloseChannel(Channel channel) private static DataBufferUtils.NestedMatchercreateMatcher(byte[] delimiter) static reactor.core.publisher.Mono<DataBuffer>join(org.reactivestreams.Publisher<? extends DataBuffer> dataBuffers) Return a newDataBuffercomposed of joining together the givendataBufferselements.static reactor.core.publisher.Mono<DataBuffer>join(org.reactivestreams.Publisher<? extends DataBuffer> buffers, int maxByteCount) Variant ofjoin(Publisher)that behaves the same way up until the specified max number of bytes to buffer.static DataBufferUtils.Matchermatcher(byte[] delimiter) Return aDataBufferUtils.Matcherfor the given delimiter.static DataBufferUtils.Matchermatcher(byte[]... delimiters) Return aDataBufferUtils.Matcherfor the given delimiters.static org.reactivestreams.Publisher<DataBuffer>outputStreamPublisher(Consumer<OutputStream> outputStreamConsumer, DataBufferFactory bufferFactory, Executor executor) Create a newPublisher<DataBuffer>based on bytes written to aOutputStream.static org.reactivestreams.Publisher<DataBuffer>outputStreamPublisher(Consumer<OutputStream> outputStreamConsumer, DataBufferFactory bufferFactory, Executor executor, int chunkSize) Creates a newPublisher<DataBuffer>based on bytes written to aOutputStream.static reactor.core.publisher.Flux<DataBuffer>read(Resource resource, long position, DataBufferFactory bufferFactory, int bufferSize) Read the givenResourceinto aFluxofDataBuffers starting at the given position.static reactor.core.publisher.Flux<DataBuffer>read(Resource resource, DataBufferFactory bufferFactory, int bufferSize) Read the givenResourceinto aFluxofDataBuffers.static reactor.core.publisher.Flux<DataBuffer>read(Path path, DataBufferFactory bufferFactory, int bufferSize, OpenOption... options) Read bytes from the given filePathinto aFluxofDataBuffers.static reactor.core.publisher.Flux<DataBuffer>readAsynchronousFileChannel(Callable<AsynchronousFileChannel> channelSupplier, long position, DataBufferFactory bufferFactory, int bufferSize) Obtain anAsynchronousFileChannelfrom the given supplier, and read it into aFluxofDataBuffers, starting at the given position.static reactor.core.publisher.Flux<DataBuffer>readAsynchronousFileChannel(Callable<AsynchronousFileChannel> channelSupplier, DataBufferFactory bufferFactory, int bufferSize) Obtain aAsynchronousFileChannelfrom the given supplier, and read it into aFluxofDataBuffers.static reactor.core.publisher.Flux<DataBuffer>readByteChannel(Callable<ReadableByteChannel> channelSupplier, DataBufferFactory bufferFactory, int bufferSize) static reactor.core.publisher.Flux<DataBuffer>readInputStream(Callable<InputStream> inputStreamSupplier, DataBufferFactory bufferFactory, int bufferSize) static booleanrelease(DataBuffer dataBuffer) Release the given data buffer.static Consumer<DataBuffer>Return a consumer that callsrelease(DataBuffer)on all passed data buffers.static <T extends DataBuffer>
Tretain(T dataBuffer) Retain the given data buffer, if it is aPooledDataBuffer.static <T extends DataBuffer>
reactor.core.publisher.Flux<T>skipUntilByteCount(org.reactivestreams.Publisher<T> publisher, long maxByteCount) Skip buffers from the givenPublisheruntil the total byte count reaches the given maximum byte count, or until the publisher is complete.static <T extends DataBuffer>
reactor.core.publisher.Flux<T>takeUntilByteCount(org.reactivestreams.Publisher<T> publisher, long maxByteCount) Relay buffers from the givenPublisheruntil the total byte count reaches the given maximum byte count, or until the publisher is complete.static <T extends DataBuffer>
TAssociate the given hint with the data buffer if it is a pooled buffer and supports leak tracking.static reactor.core.publisher.Flux<DataBuffer>write(org.reactivestreams.Publisher<? extends DataBuffer> source, AsynchronousFileChannel channel, long position) Write the given stream ofDataBuffersto the givenAsynchronousFileChannel.static reactor.core.publisher.Flux<DataBuffer>write(org.reactivestreams.Publisher<DataBuffer> source, OutputStream outputStream) Write the given stream ofDataBuffersto the givenOutputStream.static reactor.core.publisher.Flux<DataBuffer>write(org.reactivestreams.Publisher<DataBuffer> source, AsynchronousFileChannel channel) Write the given stream ofDataBuffersto the givenAsynchronousFileChannel.static reactor.core.publisher.Flux<DataBuffer>write(org.reactivestreams.Publisher<DataBuffer> source, WritableByteChannel channel) Write the given stream ofDataBuffersto the givenWritableByteChannel.static reactor.core.publisher.Mono<Void>write(org.reactivestreams.Publisher<DataBuffer> source, Path destination, OpenOption... options) Write the given stream ofDataBuffersto the given filePath.
-
字段详细资料
-
logger
-
RELEASE_CONSUMER
-
DEFAULT_CHUNK_SIZE
private static final int DEFAULT_CHUNK_SIZE- 另请参阅:
-
-
构造器详细资料
-
DataBufferUtils
public DataBufferUtils()
-
-
方法详细资料
-
readInputStream
public static reactor.core.publisher.Flux<DataBuffer> readInputStream(Callable<InputStream> inputStreamSupplier, DataBufferFactory bufferFactory, int bufferSize) Obtain anInputStreamfrom the given supplier, and read it into aFluxofDataBuffers. Closes the input stream when the Flux is terminated.- 参数:
inputStreamSupplier- the supplier for the input stream to read frombufferFactory- the factory to create data buffers withbufferSize- the maximum size of the data buffers- 返回:
- a Flux of data buffers read from the given channel
-
readByteChannel
public static reactor.core.publisher.Flux<DataBuffer> readByteChannel(Callable<ReadableByteChannel> channelSupplier, DataBufferFactory bufferFactory, int bufferSize) Obtain aReadableByteChannelfrom the given supplier, and read it into aFluxofDataBuffers. Closes the channel when the Flux is terminated.- 参数:
channelSupplier- the supplier for the channel to read frombufferFactory- the factory to create data buffers withbufferSize- the maximum size of the data buffers- 返回:
- a Flux of data buffers read from the given channel
-
readAsynchronousFileChannel
public static reactor.core.publisher.Flux<DataBuffer> readAsynchronousFileChannel(Callable<AsynchronousFileChannel> channelSupplier, DataBufferFactory bufferFactory, int bufferSize) Obtain aAsynchronousFileChannelfrom the given supplier, and read it into aFluxofDataBuffers. Closes the channel when the Flux is terminated.- 参数:
channelSupplier- the supplier for the channel to read frombufferFactory- the factory to create data buffers withbufferSize- the maximum size of the data buffers- 返回:
- a Flux of data buffers read from the given channel
-
readAsynchronousFileChannel
public static reactor.core.publisher.Flux<DataBuffer> readAsynchronousFileChannel(Callable<AsynchronousFileChannel> channelSupplier, long position, DataBufferFactory bufferFactory, int bufferSize) Obtain anAsynchronousFileChannelfrom the given supplier, and read it into aFluxofDataBuffers, starting at the given position. Closes the channel when the Flux is terminated.- 参数:
channelSupplier- the supplier for the channel to read fromposition- the position to start reading frombufferFactory- the factory to create data buffers withbufferSize- the maximum size of the data buffers- 返回:
- a Flux of data buffers read from the given channel
-
read
public static reactor.core.publisher.Flux<DataBuffer> read(Path path, DataBufferFactory bufferFactory, int bufferSize, OpenOption... options) Read bytes from the given filePathinto aFluxofDataBuffers. The method ensures that the file is closed when the flux is terminated.- 参数:
path- the path to read bytes frombufferFactory- the factory to create data buffers withbufferSize- the maximum size of the data buffers- 返回:
- a Flux of data buffers read from the given channel
-
read
public static reactor.core.publisher.Flux<DataBuffer> read(Resource resource, DataBufferFactory bufferFactory, int bufferSize) Read the givenResourceinto aFluxofDataBuffers.If the resource is a file, it is read into an
AsynchronousFileChanneland turned toFluxviareadAsynchronousFileChannel(Callable, DataBufferFactory, int)or else fall back toreadByteChannel(Callable, DataBufferFactory, int). Closes the channel when the flux is terminated.- 参数:
resource- the resource to read frombufferFactory- the factory to create data buffers withbufferSize- the maximum size of the data buffers- 返回:
- a Flux of data buffers read from the given channel
-
read
public static reactor.core.publisher.Flux<DataBuffer> read(Resource resource, long position, DataBufferFactory bufferFactory, int bufferSize) Read the givenResourceinto aFluxofDataBuffers starting at the given position.If the resource is a file, it is read into an
AsynchronousFileChanneland turned toFluxviareadAsynchronousFileChannel(Callable, DataBufferFactory, int)or else fall back onreadByteChannel(Callable, DataBufferFactory, int). Closes the channel when the flux is terminated.- 参数:
resource- the resource to read fromposition- the position to start reading frombufferFactory- the factory to create data buffers withbufferSize- the maximum size of the data buffers- 返回:
- a Flux of data buffers read from the given channel
-
write
public static reactor.core.publisher.Flux<DataBuffer> write(org.reactivestreams.Publisher<DataBuffer> source, OutputStream outputStream) Write the given stream ofDataBuffersto the givenOutputStream. Does not close the output stream when the flux is terminated, and does not release the data buffers in the source. If releasing is required, then subscribe to the returnedFluxwith areleaseConsumer().Note that the writing process does not start until the returned
Fluxis subscribed to.- 参数:
source- the stream of data buffers to be writtenoutputStream- the output stream to write to- 返回:
- a Flux containing the same buffers as in
source, that starts the writing process when subscribed to, and that publishes any writing errors and the completion signal
-
write
public static reactor.core.publisher.Flux<DataBuffer> write(org.reactivestreams.Publisher<DataBuffer> source, WritableByteChannel channel) Write the given stream ofDataBuffersto the givenWritableByteChannel. Does not close the channel when the flux is terminated, and does not release the data buffers in the source. If releasing is required, then subscribe to the returnedFluxwith areleaseConsumer().Note that the writing process does not start until the returned
Fluxis subscribed to.- 参数:
source- the stream of data buffers to be writtenchannel- the channel to write to- 返回:
- a Flux containing the same buffers as in
source, that starts the writing process when subscribed to, and that publishes any writing errors and the completion signal
-
write
public static reactor.core.publisher.Flux<DataBuffer> write(org.reactivestreams.Publisher<DataBuffer> source, AsynchronousFileChannel channel) Write the given stream ofDataBuffersto the givenAsynchronousFileChannel. Does not close the channel when the flux is terminated, and does not release the data buffers in the source. If releasing is required, then subscribe to the returnedFluxwith areleaseConsumer().Note that the writing process does not start until the returned
Fluxis subscribed to.- 参数:
source- the stream of data buffers to be writtenchannel- the channel to write to- 返回:
- a Flux containing the same buffers as in
source, that starts the writing process when subscribed to, and that publishes any writing errors and the completion signal
-
write
public static reactor.core.publisher.Flux<DataBuffer> write(org.reactivestreams.Publisher<? extends DataBuffer> source, AsynchronousFileChannel channel, long position) Write the given stream ofDataBuffersto the givenAsynchronousFileChannel. Does not close the channel when the flux is terminated, and does not release the data buffers in the source. If releasing is required, then subscribe to the returnedFluxwith areleaseConsumer().Note that the writing process does not start until the returned
Fluxis subscribed to.- 参数:
source- the stream of data buffers to be writtenchannel- the channel to write toposition- the file position where writing is to begin; must be non-negative- 返回:
- a flux containing the same buffers as in
source, that starts the writing process when subscribed to, and that publishes any writing errors and the completion signal
-
write
public static reactor.core.publisher.Mono<Void> write(org.reactivestreams.Publisher<DataBuffer> source, Path destination, OpenOption... options) Write the given stream ofDataBuffersto the given filePath. The optionaloptionsparameter specifies how the file is created or opened (defaults toCREATE,TRUNCATE_EXISTING, andWRITE).- 参数:
source- the stream of data buffers to be writtendestination- the path to the fileoptions- the options specifying how the file is opened- 返回:
- a
Monothat indicates completion or error
-
checkWriteOptions
-
closeChannel
-
outputStreamPublisher
public static org.reactivestreams.Publisher<DataBuffer> outputStreamPublisher(Consumer<OutputStream> outputStreamConsumer, DataBufferFactory bufferFactory, Executor executor) Create a newPublisher<DataBuffer>based on bytes written to aOutputStream.- The parameter
outputStreamConsumeris invoked once per subscription of the returnedPublisher, when the first item is requested. OutputStream.write()invocations made byoutputStreamConsumerare buffered until they exceed the default chunk size of 1024, or when the stream is flushed and then result in a published item if there is demand.- If there is no demand,
OutputStream.write()will block until there is. - If the subscription is cancelled,
OutputStream.write()will throw aIOException. - The subscription is
completed when
outputStreamHandlercompletes. - Any exceptions thrown from
outputStreamHandlerwill be dispatched to the Subscriber.
- 参数:
outputStreamConsumer- invoked when the first buffer is requestedexecutor- used to invoke theoutputStreamHandler- 返回:
- a
Publisher<DataBuffer>based on bytes written byoutputStreamHandler
- The parameter
-
outputStreamPublisher
public static org.reactivestreams.Publisher<DataBuffer> outputStreamPublisher(Consumer<OutputStream> outputStreamConsumer, DataBufferFactory bufferFactory, Executor executor, int chunkSize) Creates a newPublisher<DataBuffer>based on bytes written to aOutputStream.- The parameter
outputStreamConsumeris invoked once per subscription of the returnedPublisher, when the first item is requested. OutputStream.write()invocations made byoutputStreamHandlerare buffered until they reach or exceedchunkSize, or when the stream is flushed and then result in a published item if there is demand.- If there is no demand,
OutputStream.write()will block until there is. - If the subscription is cancelled,
OutputStream.write()will throw aIOException. - The subscription is
completed when
outputStreamHandlercompletes. - Any exceptions thrown from
outputStreamHandlerwill be dispatched to the Subscriber.
- 参数:
outputStreamConsumer- invoked when the first buffer is requestedexecutor- used to invoke theoutputStreamHandlerchunkSize- minimum size of the buffer produced by the publisher- 返回:
- a
Publisher<DataBuffer>based on bytes written byoutputStreamHandler
- The parameter
-
takeUntilByteCount
public static <T extends DataBuffer> reactor.core.publisher.Flux<T> takeUntilByteCount(org.reactivestreams.Publisher<T> publisher, long maxByteCount) Relay buffers from the givenPublisheruntil the total byte count reaches the given maximum byte count, or until the publisher is complete.- 参数:
publisher- the publisher to filtermaxByteCount- the maximum byte count- 返回:
- a flux whose maximum byte count is
maxByteCount
-
skipUntilByteCount
public static <T extends DataBuffer> reactor.core.publisher.Flux<T> skipUntilByteCount(org.reactivestreams.Publisher<T> publisher, long maxByteCount) Skip buffers from the givenPublisheruntil the total byte count reaches the given maximum byte count, or until the publisher is complete.- 参数:
publisher- the publisher to filtermaxByteCount- the maximum byte count- 返回:
- a flux with the remaining part of the given publisher
-
retain
Retain the given data buffer, if it is aPooledDataBuffer.- 参数:
dataBuffer- the data buffer to retain- 返回:
- the retained buffer
-
touch
Associate the given hint with the data buffer if it is a pooled buffer and supports leak tracking.- 参数:
dataBuffer- the data buffer to attach the hint tohint- the hint to attach- 返回:
- the input buffer
-
release
Release the given data buffer. If it is aPooledDataBufferand has been allocated, this method will callPooledDataBuffer.release(). If it is aCloseableDataBuffer, this method will callCloseableDataBuffer.close().- 参数:
dataBuffer- the data buffer to release- 返回:
trueif the buffer was released;falseotherwise.
-
releaseConsumer
Return a consumer that callsrelease(DataBuffer)on all passed data buffers. -
join
public static reactor.core.publisher.Mono<DataBuffer> join(org.reactivestreams.Publisher<? extends DataBuffer> dataBuffers) Return a newDataBuffercomposed of joining together the givendataBufferselements. Depending on theDataBuffertype, 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.If
dataBuffersproduces an error or if there is a cancel signal, then all accumulated buffers will be released.Note that the given data buffers do not have to be released. They will be released as part of the returned composite.
- 参数:
dataBuffers- the data buffers that are to be composed- 返回:
- a buffer that is composed of the
dataBuffersargument
-
join
public static reactor.core.publisher.Mono<DataBuffer> join(org.reactivestreams.Publisher<? extends DataBuffer> buffers, int maxByteCount) Variant ofjoin(Publisher)that behaves the same way up until the specified max number of bytes to buffer. Once the limit is exceeded,DataBufferLimitExceptionis raised.- 参数:
buffers- the data buffers that are to be composedmaxByteCount- the max number of bytes to buffer, or -1 for unlimited- 返回:
- a buffer with the aggregated content, possibly an empty Mono if the max number of bytes to buffer is exceeded.
- 抛出:
DataBufferLimitException- if maxByteCount is exceeded
-
matcher
Return aDataBufferUtils.Matcherfor the given delimiter. The matcher can be used to find the delimiters in a stream of data buffers.- 参数:
delimiter- the delimiter bytes to find- 返回:
- the matcher
-
matcher
Return aDataBufferUtils.Matcherfor the given delimiters. The matcher can be used to find the delimiters in a stream of data buffers.- 参数:
delimiters- the delimiters bytes to find- 返回:
- the matcher
-
createMatcher
-