spring-projects / spring-framework

Spring Framework
https://spring.io/projects/spring-framework
Apache License 2.0
56.75k stars 38.15k forks source link

DataBufferUtils and BodyInserters: allow consumers of OutputStream to throw IOException #33830

Open fedpet opened 3 weeks ago

fedpet commented 3 weeks ago

At the moment, users of DataBufferUtils.outputStreamPublisher are forced to catch and re-throw IOException whenever they actually write to the OutputStream.

Example:

DataBufferUtils.outputStreamPublisher(
    outputStream -> {
        try {
            outputStream.write(1);
            ...
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    },
new DefaultDataBufferFactory(),
Runnable::run)

This PR aims to allow users to write cleaner code, example:

DataBufferUtils.outputStreamPublisher(
    outputStream -> {
        outputStream.write(1);
        ...
    },
new DefaultDataBufferFactory(),
Runnable::run)

As exceptions are already handled nicely under the hoods.

Same concept for BodyInserters.

pivotal-cla commented 3 weeks ago

@fedpet Please sign the Contributor License Agreement!

Click here to manually synchronize the status of this Pull Request.

See the FAQ for frequently asked questions.

pivotal-cla commented 3 weeks ago

@fedpet Thank you for signing the Contributor License Agreement!