Top Description Inners Fields Constructors Methods
org.springframework.core.io.buffer

public abstract Class DataBufferUtils

extends Object
Class Inheritance
Imports
java.io.File, .IOException, .InputStream, .OutputStream, java.nio.ByteBuffer, java.nio.channels.AsynchronousFileChannel, .Channel, .Channels, .CompletionHandler, .ReadableByteChannel, .WritableByteChannel, java.nio.file.OpenOption, .Path, .StandardOpenOption, java.util.HashSet, .Set, java.util.concurrent.Callable, .Executor, java.util.concurrent.atomic.AtomicBoolean, .AtomicLong, .AtomicReference, java.util.function.Consumer, org.apache.commons.logging.Log, .LogFactory, org.reactivestreams.Publisher, .Subscriber, .Subscription, reactor.core.publisher.BaseSubscriber, .Flux, .FluxSink, .Mono, .SynchronousSink, reactor.util.context.Context, org.springframework.core.io.Resource, org.springframework.lang.Nullable, org.springframework.util.Assert

Utility class for working with DataBuffers.
Authors
Arjen Poutsma, Brian Clozel
Since
5.0

Nested and Inner Type Summary

Modifier and TypeClass and Description
private abstract static class
private static class
DataBufferUtils.CompositeMatcher

Matcher that supports searching for multiple delimiters.

private static class
DataBufferUtils.KnuthMorrisPrattMatcher

Implementation of Matcher that uses the Knuth-Morris-Pratt algorithm.

public static interface
DataBufferUtils.Matcher

Contract to find delimiter(s) against one or more data buffers that can be passed one at a time to the match(DataBuffer) method.

private static interface
DataBufferUtils.NestedMatcher

Matcher that can be nested within CompositeMatcher where multiple matchers advance together using the same index, one byte at a time.

private static class
private static class
private static class
DataBufferUtils.SingleByteMatcher

Matcher for a single byte delimiter.

private static class
DataBufferUtils.TwoByteMatcher

Matcher with a 2 byte delimiter that does not benefit from a Knuth-Morris-Pratt suffix-prefix table.

private static class
private static class

Field Summary

Modifier and TypeField and Description
private static final int
private static final Log
private static final Consumer<DataBuffer>

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private static Set<OpenOption>
pack-priv static void
private static DataBufferUtils.NestedMatcher
createMatcher(byte[] delimiter)

public static Mono<DataBuffer>

Returns:

a buffer that is composed of the dataBuffers argument
join
(Publisher<? extends DataBuffer>
the data buffers that are to be composed
dataBuffers
)

Return a new DataBuffer composed of joining together the given dataBuffers elements.

public static Mono<DataBuffer>

Returns:

a buffer with the aggregated content, possibly an empty Mono if the max number of bytes to buffer is exceeded.
join
(Publisher<? extends DataBuffer>
the data buffers that are to be composed
buffers
,
int
the max number of bytes to buffer, or -1 for unlimited
maxByteCount
)

Variant of join(Publisher) that behaves the same way up until the specified max number of bytes to buffer.

public static DataBufferUtils.Matcher

Returns:

the matcher
matcher
(byte[]
the delimiter bytes to find
delimiter
)

Return a Matcher for the given delimiter.

public static DataBufferUtils.Matcher

Returns:

the matcher
matcher
(byte[]...
the delimiters bytes to find
delimiters
)

Return a Matcher for the given delimiters.

public static Publisher<DataBuffer>

Returns:

a Publisher<DataBuffer> based on bytes written by outputStreamHandler
outputStreamPublisher
(Consumer<OutputStream>
invoked when the first buffer is requested
outputStreamConsumer
,
DataBufferFactory bufferFactory, Executor
used to invoke the outputStreamHandler
executor
)

Create a new Publisher<DataBuffer> based on bytes written to a OutputStream.

public static Publisher<DataBuffer>

Returns:

a Publisher<DataBuffer> based on bytes written by outputStreamHandler
outputStreamPublisher
(Consumer<OutputStream>
invoked when the first buffer is requested
outputStreamConsumer
,
DataBufferFactory bufferFactory, Executor
used to invoke the outputStreamHandler
executor
,
int
minimum size of the buffer produced by the publisher
chunkSize
)

Creates a new Publisher<DataBuffer> based on bytes written to a OutputStream.

public static Flux<DataBuffer>

Returns:

a Flux of data buffers read from the given channel
read
(Path
the path to read bytes from
path
,
DataBufferFactory
the factory to create data buffers with
bufferFactory
,
int
the maximum size of the data buffers
bufferSize
,
OpenOption... options)

Read bytes from the given file Path into a Flux of DataBuffers.

public static Flux<DataBuffer>

Returns:

a Flux of data buffers read from the given channel
read
(Resource
the resource to read from
resource
,
DataBufferFactory
the factory to create data buffers with
bufferFactory
,
int
the maximum size of the data buffers
bufferSize
)

Read the given Resource into a Flux of DataBuffers.

public static Flux<DataBuffer>

Returns:

a Flux of data buffers read from the given channel
read
(Resource
the resource to read from
resource
,
long
the position to start reading from
position
,
DataBufferFactory
the factory to create data buffers with
bufferFactory
,
int
the maximum size of the data buffers
bufferSize
)

Read the given Resource into a Flux of DataBuffers starting at the given position.

public static Flux<DataBuffer>

Returns:

a Flux of data buffers read from the given channel
readAsynchronousFileChannel
(Callable<AsynchronousFileChannel>
the supplier for the channel to read from
channelSupplier
,
DataBufferFactory
the factory to create data buffers with
bufferFactory
,
int
the maximum size of the data buffers
bufferSize
)

Obtain a AsynchronousFileChannel from the given supplier, and read it into a Flux of DataBuffers.

public static Flux<DataBuffer>

Returns:

a Flux of data buffers read from the given channel
readAsynchronousFileChannel
(Callable<AsynchronousFileChannel>
the supplier for the channel to read from
channelSupplier
,
long
the position to start reading from
position
,
DataBufferFactory
the factory to create data buffers with
bufferFactory
,
int
the maximum size of the data buffers
bufferSize
)

Obtain an AsynchronousFileChannel from the given supplier, and read it into a Flux of DataBuffers, starting at the given position.

public static Flux<DataBuffer>

Returns:

a Flux of data buffers read from the given channel
readByteChannel
(Callable<ReadableByteChannel>
the supplier for the channel to read from
channelSupplier
,
DataBufferFactory
the factory to create data buffers with
bufferFactory
,
int
the maximum size of the data buffers
bufferSize
)

Obtain a ReadableByteChannel from the given supplier, and read it into a Flux of DataBuffers.

public static Flux<DataBuffer>

Returns:

a Flux of data buffers read from the given channel
readInputStream
(Callable<InputStream>
the supplier for the input stream to read from
inputStreamSupplier
,
DataBufferFactory
the factory to create data buffers with
bufferFactory
,
int
the maximum size of the data buffers
bufferSize
)

Obtain an InputStream from the given supplier, and read it into a Flux of DataBuffers.

public static boolean

Returns:

true if the buffer was released; false otherwise.
release
(DataBuffer
the data buffer to release
dataBuffer
)

Release the given data buffer.

public static Consumer<DataBuffer>
releaseConsumer()

Return a consumer that calls release(DataBuffer) on all passed data buffers.

public static <T extends DataBuffer> T

Returns:

the retained buffer
retain
(T
the data buffer to retain
dataBuffer
)

Retain the given data buffer, if it is a PooledDataBuffer.

public static <T extends DataBuffer> Flux<T>

Returns:

a flux with the remaining part of the given publisher
skipUntilByteCount
(Publisher<T>
the publisher to filter
publisher
,
long
the maximum byte count
maxByteCount
)

Skip buffers from the given Publisher until the total byte count reaches the given maximum byte count, or until the publisher is complete.

public static <T extends DataBuffer> Flux<T>

Returns:

a flux whose maximum byte count is maxByteCount
takeUntilByteCount
(Publisher<T>
the publisher to filter
publisher
,
long
the maximum byte count
maxByteCount
)

Relay buffers from the given Publisher until the total byte count reaches the given maximum byte count, or until the publisher is complete.

public static <T extends DataBuffer> T

Returns:

the input buffer
touch
(T
the data buffer to attach the hint to
dataBuffer
,
Object
the hint to attach
hint
)

Associate the given hint with the data buffer if it is a pooled buffer and supports leak tracking.

public static Flux<DataBuffer>

Returns:

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
(Publisher<DataBuffer>
the stream of data buffers to be written
source
,
OutputStream
the output stream to write to
outputStream
)

Write the given stream of DataBuffers to the given OutputStream.

public static Flux<DataBuffer>

Returns:

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
(Publisher<DataBuffer>
the stream of data buffers to be written
source
,
WritableByteChannel
the channel to write to
channel
)

Write the given stream of DataBuffers to the given WritableByteChannel.

public static Flux<DataBuffer>

Returns:

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
(Publisher<DataBuffer>
the stream of data buffers to be written
source
,
AsynchronousFileChannel
the channel to write to
channel
)

Write the given stream of DataBuffers to the given AsynchronousFileChannel.

public static Flux<DataBuffer>

Returns:

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
(Publisher<? extends DataBuffer>
the stream of data buffers to be written
source
,
AsynchronousFileChannel
the channel to write to
channel
,
long
the file position where writing is to begin; must be non-negative
position
)

Write the given stream of DataBuffers to the given AsynchronousFileChannel.

public static Mono<Void>

Returns:

a Mono that indicates completion or error
write
(Publisher<DataBuffer>
the stream of data buffers to be written
source
,
Path
the path to the file
destination
,
OpenOption...
the options specifying how the file is opened
options
)

Write the given stream of DataBuffers to the given file Path.

Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait