All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.zalando.riptide.compression.WrappingHttpOutputMessage Maven / Gradle / Ivy

There is a newer version: 4.1.0
Show newest version
package org.zalando.riptide.compression;

import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpOutputMessage;
import org.zalando.fauxpas.ThrowingUnaryOperator;

import javax.annotation.Nonnull;
import java.io.IOException;
import java.io.OutputStream;

@RequiredArgsConstructor
final class WrappingHttpOutputMessage implements HttpOutputMessage, AutoCloseable {

    private final HttpOutputMessage message;
    private final ThrowingUnaryOperator wrapper;
    private OutputStream stream;

    @Nonnull
    @Override
    public OutputStream getBody() throws IOException {
        if (stream == null) {
            stream = wrapper.apply(message.getBody());
        }
        return stream;
    }

    @Nonnull
    @Override
    public HttpHeaders getHeaders() {
        return message.getHeaders();
    }

    @Override
    public void close() throws IOException {
        // make sure any underlying compressor gets flushed
        if (stream != null) {
            stream.close();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy