Search in sources :

Example 1 with NettyStreamedCustomizableResponseType

use of io.micronaut.http.server.netty.types.stream.NettyStreamedCustomizableResponseType in project micronaut-core by micronaut-projects.

the class StreamTypeHandler method handle.

@Override
public void handle(Object object, HttpRequest<?> request, MutableHttpResponse<?> response, ChannelHandlerContext context) {
    NettyStreamedCustomizableResponseType type;
    if (object instanceof InputStream) {
        type = () -> (InputStream) object;
    } else if (object instanceof NettyStreamedCustomizableResponseType) {
        type = (NettyStreamedCustomizableResponseType) object;
    } else {
        throw new CustomizableResponseTypeException("StreamTypeHandler only supports InputStream or StreamedCustomizableResponseType types");
    }
    type.process(response);
    type.write(request, response, context);
    context.read();
}
Also used : InputStream(java.io.InputStream) NettyStreamedCustomizableResponseType(io.micronaut.http.server.netty.types.stream.NettyStreamedCustomizableResponseType) CustomizableResponseTypeException(io.micronaut.http.server.types.CustomizableResponseTypeException)

Aggregations

NettyStreamedCustomizableResponseType (io.micronaut.http.server.netty.types.stream.NettyStreamedCustomizableResponseType)1 CustomizableResponseTypeException (io.micronaut.http.server.types.CustomizableResponseTypeException)1 InputStream (java.io.InputStream)1