
io.micronaut.http.server.netty.body.StreamingMultiObjectBody Maven / Gradle / Ivy
/*
* Copyright 2017-2023 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.http.server.netty.body;
import io.micronaut.core.annotation.Internal;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.http.netty.reactive.HotObservable;
import io.micronaut.http.server.netty.FormRouteCompleter;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.ByteBufAllocator;
import io.netty.util.ReferenceCountUtil;
import org.reactivestreams.Publisher;
import org.reactivestreams.Subscriber;
import org.reactivestreams.Subscription;
import reactor.core.publisher.Flux;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InterruptedIOException;
import java.util.concurrent.locks.Condition;
import java.util.concurrent.locks.Lock;
import java.util.concurrent.locks.ReentrantLock;
import java.util.function.Function;
/**
* {@link MultiObjectBody} derived from a {@link StreamingByteBody}. Operations are lazy.
*
* @since 4.0.0
* @author Jonas Konrad
*/
@Internal
public final class StreamingMultiObjectBody extends ManagedBody> implements MultiObjectBody {
StreamingMultiObjectBody(Publisher> publisher) {
super(publisher);
}
@Override
void release(Publisher> value) {
if (value instanceof HotObservable> hot) {
hot.closeIfNoSubscriber();
}
}
@Override
public InputStream coerceToInputStream(ByteBufAllocator alloc) {
PublisherAsBlocking publisherAsBlocking = new PublisherAsBlocking<>();
//noinspection unchecked
((Publisher) claim()).subscribe(publisherAsBlocking);
return new PublisherAsStream(publisherAsBlocking);
}
@Override
public Publisher> asPublisher() {
return claim();
}
@Override
public MultiObjectBody mapNotNull(Function
© 2015 - 2025 Weber Informatics LLC | Privacy Policy