spring-framework / org.springframework.core.io.buffer / DataBufferUtils

DataBufferUtils

abstract class DataBufferUtils

Utility class for working with DataBuffers.

Author
Arjen Poutsma

Author
Brian Clozel

Since
5.0

Constructors

<init>

DataBufferUtils()

Utility class for working with DataBuffers.

Functions

read

open static fun read(inputStream: InputStream, dataBufferFactory: DataBufferFactory, bufferSize: Int): Flux<DataBuffer>

Read the given InputStream into a Flux of DataBuffers. Closes the input stream when the flux is terminated.

open static fun read(channel: ReadableByteChannel, dataBufferFactory: DataBufferFactory, bufferSize: Int): Flux<DataBuffer>

Read the given ReadableByteChannel into a Flux of DataBuffers. Closes the channel when the flux is terminated.

open static fun read(channel: AsynchronousFileChannel, dataBufferFactory: DataBufferFactory, bufferSize: Int): Flux<DataBuffer>

Read the given AsynchronousFileChannel into a Flux of DataBuffers. Closes the channel when the flux is terminated.

open static fun read(channel: AsynchronousFileChannel, position: Long, dataBufferFactory: DataBufferFactory, bufferSize: Int): Flux<DataBuffer>

Read the given AsynchronousFileChannel into a Flux of DataBuffers, starting at the given position. Closes the channel when the flux is terminated.

open static fun read(resource: Resource, dataBufferFactory: DataBufferFactory, bufferSize: Int): Flux<DataBuffer>

Read the given Resource into a Flux of DataBuffers.

If the resource is a file, it is read into an AsynchronousFileChannel and turned to Flux via #read(AsynchronousFileChannel, DataBufferFactory, int) or else fall back on #read(InputStream, DataBufferFactory, int) closes the channel when the flux is terminated.

open static fun read(resource: Resource, position: Long, dataBufferFactory: DataBufferFactory, bufferSize: Int): Flux<DataBuffer>

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

If the resource is a file, it is read into an AsynchronousFileChannel and turned to Flux via #read(AsynchronousFileChannel, DataBufferFactory, int) or else fall back on #read(InputStream, DataBufferFactory, int). Closes the channel when the flux is terminated.

release

open static fun release(dataBuffer: DataBuffer): Boolean

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

releaseConsumer

open static fun releaseConsumer(): Consumer<DataBuffer>

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

retain

open static fun <T : DataBuffer> retain(dataBuffer: T): T

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

skipUntilByteCount

open static fun skipUntilByteCount(publisher: Publisher<DataBuffer>, maxByteCount: Long): Flux<DataBuffer>

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

takeUntilByteCount

open static fun takeUntilByteCount(publisher: Publisher<DataBuffer>, maxByteCount: Long): Flux<DataBuffer>

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

write

open static fun write(source: Publisher<DataBuffer>, outputStream: OutputStream): Flux<DataBuffer>

Write the given stream of DataBuffers to the given OutputStream. 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 returned Flux with a #releaseConsumer().

Note that the writing process does not start until the returned Flux is subscribed to.

open static fun write(source: Publisher<DataBuffer>, channel: WritableByteChannel): Flux<DataBuffer>

Write the given stream of DataBuffers to the given WritableByteChannel. 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 returned Flux with a #releaseConsumer().

Note that the writing process does not start until the returned Flux is subscribed to.

open static fun write(source: Publisher<DataBuffer>, channel: AsynchronousFileChannel, position: Long): Flux<DataBuffer>

Write the given stream of DataBuffers to the given AsynchronousFileChannel. 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 returned Flux with a #releaseConsumer().

Note that the writing process does not start until the returned Flux is subscribed to.